Install MySQL 5.7.11 for Linux Generic binary in CentOS 7 using the command line
The latest version of MySQL is 5.7.11. in Linux, the installation package of a specific release version is provided (for example, .rpmloud and a general version installation package (.tar.gz ). In general, many projects tend to use the binary universal installation package for installation and configuration, which is very convenient to customize. However, during the installation process, it was found that the installation instruction file provided by the official website is too simple, and there are still problems with the parameters in the file. After execution, the mysql Service Startup reports an error, after finding some information and experimenting with it, I will summarize a set of practical installation and configuration procedures, as shown below:
1. Download the MySQL for Linux Generic binary fuse installation package (.tar.gz). The following uses version 5.7.11 as an example.
2. I usually use to install MySQL under the/opt directory, So I copied the MySQL installation package file to the/opt directory, switched to the root account, and executed the following command:
# tar -zxvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz# ln -s mysql-5.7.11-linux-glibc2.5-x86_64 mysql # cd mysql
A mysql soft connection is established to facilitate configuration and operations in the future.
3. the MySQL directory obtained after the common binary installation package of version 5.7.11 is decompressed does not contain the directory where data files are stored. Therefore, you need to create a subdirectory separately to store data files, for example, named data, after the command in step 2 (ensure that the directory is in the/opt/mysql directory), continue to execute the following command:
# groupadd mysql# useradd -r -g mysql -s /bin/false mysql# mkdir data# chown -R root:root .# bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data# bin/mysql_ssl_rsa_setup --datadir=/opt/mysql/data
Specifically, MySQL initialization starts with the mysqld -- initialize command starting from 5.7.6 and stops using the mysql_install_db command. However, the mysqld -- initialize Command provided in the official documentation does not provide the -- basedir and -- datadir parameters, because it uses the/etc/my. cnf configuration file by default. Some Linux distributions may generate the mysql configuration file and save it in the/etc directory by default during installation, while basedir and datadir in the default configuration file are commented out, there is no actual content, so mysqld still does not know which directory the current basedir and datadir are. Therefore, the command line parameter is used to specify the custom directory. The mysql_ssl_rsa_setup command also specifies the datadir directory, because the key files required by the database are also stored together with the data files, both in the datadir directory.
4. After completing the above work, start the database service without panic, and then create the MySQL service configuration file my. cnf. This file can find a configuration sample file named my-default.cnf under the/opt/mysql/support-files subdirectory, and then copy it out, renamed my. put cnf in/opt/mysql. According to MySQL rules, its configuration file must be my. cnf name. The read order is to first try to read/etc/my. cnf. If it does not exist, read my. cnf. If the system environment variable does not have basedir, try to read my. cnf:/opt/mysql/my. if cnf does not exist, read the contents in the current user's home directory. mysql/my. cnf ). Therefore, we only need to ensure that there is a my. cnf under/opt/mysql, and the modification content is as follows:
basedir = /opt/mysqldatadir = /opt/mysql/datalog-error = /var/log/mysql-error.log
The rest remain unchanged. According to the official documentation, log-error is used to specify the path of the running information log file after the service is started. The running information includes Notice, Error, and other types of logs.
5. After the configuration file is modified and saved, you can start the service, make sure that the current directory is/opt/mysql, and then run the following command:
# bin/msyqld_safe --user=mysql &
Then the service can be started normally. You can also run the netstat-na-t command to check whether port 3306 of the MySQL service is in the listening status. If yes, the service starts normally. Of course, you can also view the contents of the log file to determine, we here because you have specified the log file as/var/log/mysql-error.log in the configuration file, so you can view the file.
6. log on to the MySQL service on the local machine. logons with an empty root password are not allowed from version 5.7.10. In fact, after executing mysqld -- initialize, the system will generate an initialization password for the root user and display it in the standard output on the screen. Remember this! After you log on with this password for the first time, you can change the password. Assume that the initial password generated by the system is xxxxxx. The command is as follows:
# bin/mysql --user=root --password=xxxxxx
In this way, you can log on to the MySQL server.
7. After logon, the system requires you to change the password of the root account. The MySQL Command is as follows:
mysql> set password=password('1234');
In this way, you can change the root account to 1234.
8. For the sake of security in Linux, by default, the MySQL database service cannot be accessed by machines other than the MySQL server. Therefore, you need to re-authorize the root account. To facilitate remote access to the MySQL server from other machines, the MySQL Command is as follows:
mysql> grant all privileges on *.* to root@'%' identified by '1234';mysql> flush privileges;
In this way, you can remotely log on to the MySQL server from other machines with the root account. You can use the following MySQL command to verify it:
mysql> use mysql;mysql> select host,user from user;+-----------+-----------+| host | user |+-----------+-----------+| % | root || localhost | mysql.sys || localhost | root |+-----------+-----------+3 rows in set (0.00 sec)
This proves that the system table user has added a record about root remote logon.