I. MySQL Installation Method
There are two ways to install MySQL under Ubuntu:
1. By command, as follows:
sudo apt-get install mysql-server
apt-get isntall mysql-client
sudo apt-get install libmysqlclient-dev
It's easy to install MySQL by command, but only the latest version of MySQL can be installed, so you can't choose the version you need.
2. By downloading the installation package, this article mainly explains the installation method.
MySQL Download
The Mysql download address for all platforms is: MySQL Download . Note that before downloading, you need to determine the version of your system. This article uses Ubuntu system to check the version of Ubuntu system with a command:
root@xlg:~/MySQL/package# cat /etc/issue
Ubuntu 14.04.4 LTS \n \l
This article downloads mysql-server_5.7.19-1 ubuntu14.04_amd64.deb-bundle.tar, which contains all the required installation packages. Execute the command to decompress:
tar xf mysql-server_5.7.19-1ubuntu14.04_amd64.deb-bundle.tar
After decompression, the following files are included:
libmysqlclient20_5.7.19-1ubuntu14.04_amd64.deb
libmysqlclient-dev_5.7.19-1ubuntu14.04_amd64.deb
libmysqld-dev_5.7.19-1ubuntu14.04_amd64.deb
mysql-client_5.7.19-1ubuntu14.04_amd64.deb
mysql-common_5.7.19-1ubuntu14.04_amd64.deb
mysql-community-client_5.7.19-1ubuntu14.04_amd64.deb
mysql-community-server_5.7.19-1ubuntu14.04_amd64.deb
mysql-community-source_5.7.19-1ubuntu14.04_amd64.deb
mysql-community-test_5.7.19-1ubuntu14.04_amd64.deb
mysql-server_5.7.19-1ubuntu14.04_amd64.deb
mysql-testsuite_5.7.19-1ubuntu14.04_amd64.deb
III. MySQL Installation
Installing dependency packages using dpkg
dpkg -i mysql-common_5.7.19-1ubuntu14.04_amd64.deb
dpkg -i libmysqlclient20_5.7.19-1ubuntu14.04_amd64.deb
dpkg -i libmysqlclient-dev_5.7.19-1ubuntu14.04_amd64.deb
dpkg -i libmysqld-dev_5.7.19-1ubuntu14.04_amd64.deb
dpkg -i mysql-community-client_5.7.19-1ubuntu14.04_amd64.deb
dpkg -i mysql-client_5.7.19-1ubuntu14.04_amd64.deb
dpkg -i mysql-community-source_5.7.19-1ubuntu14.04_amd64.deb
dpkg -i mysql-community-server_5.7.19-1ubuntu14.04_amd64.deb
The last instruction above will report the following error:
dpkg: dependency problems prevent configuration of mysql-community-server:
mysql-community-server depends on libmecab2 (>= 0.996-1.1); however: Package libmecab2 is not installed.
From the above error, we can see that libmecab2 library is missing. Use the following command to install:
apt-get install libmecab2
The database password will be prompted during installation. After the libmecab2 library is installed, the command is re-executed:
dpkg -i mysql-community-server_5.7.19-1ubuntu14.04_amd64.deb
The installation of MySQL database can be completed.
IV. Verify MySQL Installation
After the successful installation of MySQL, some basic tables will be initialized. After the server starts up, you can verify whether MySQL works properly through simple tests.
Use the mysqladmin command to check the version of the server. On linux, the binary file is located in / usr/bin on linux. The following is the result of the command run.
root@xlg:~/MySQL/package# mysqladmin --version
mysqladmin Ver 8.42 Distrib 5.7.19, for Linux on x86_64
As shown above, it means that the MySQL database has been successfully installed. If no information is entered after the above command is executed, it means that your MySQL database has not been successfully installed.
5. Use MySQL Client(MySQL Client) to execute simple SQL commands
You can connect to MySQL server using MySQL command in MySQL Client(MySQL client), as follows:
root@xlg:~/MySQL/package# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
When the above command is executed, the MySQL > prompt will be output, which indicates that you have successfully connected to the MySQL server. You can execute the SQL command at the MySQL > prompt:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
6. Modifying Password
The following commands can be used to create passwords for root users:
# mysqladmin -u root password "new_password";
Now you can connect to the MySQL server with the following commands:
root@xlg:~/MySQL/package# mysql -u root -p
Enter password:
Note: When entering a password, the password will not be displayed. You can enter it correctly.
7. Start MySQL on Linux System Startup
If you need to start the MySQL server when the Linux system starts, you need to add the following commands in the / etc/rc.local file:
/etc/init.d/mysqld start
Of course, you need to add mysqld binaries to / etc/init.d / directory.