1. Preparation before installation
1. Check whether mysql has been installed, execute the command:
[root@kaypc ~]# rpm -qa | grep mysql
If you have installed mysql, execute the delete command:
[root@localhost /]# rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64
2. Query all the folders corresponding to Mysql:
[root@kaypc ~]# whereis mysql
[root@kaypc ~]# find / -name mysql
Delete the relevant directory or file rm -rf to verify whether the deletion is complete
3. Check whether the mysql user group and user exist (uninstall delete and install add):
[root@kaypc ~]# cat /etc/group | grep mysql
[root@kaypc ~]# cat /etc/passwd |grep mysql
If it exists, press uninstall to delete:
[root@kaypc ~]# userdel mysql
Prompt that the process is occupying, because the mysql service was not stopped during uninstallation, and the process was forcibly killed:
[root@kaypc ~]# kill -9 28018 #再删除mysql用户
Delete the mysql user group:
[root@kaypc ~]# groupdel mysql
Install new users and user groups
[root@kaypc ~]# cat /etc/group | grep mysql
[root@kaypc ~]# cat /etc/passwd |grep mysql
[root@kaypc ~]# groupadd mysql
[root@kaypc ~]# useradd -r -g mysql mysql
4. Download from the official website is the Mysql installation package download command for Linux :
[root@kaypc ~]# yum install wget -y
[root@kaypc ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
Wait for the download to complete, or you can directly go to the mysql official website and select the corresponding version to download the installation package.
2. Install MySQL
1. Find the Mysql installation package in the directory where the wget command is executed or in your upload directory: mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
Execute the decompression command:
[root@kaypc ~]# tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
After the decompression is complete, you can see that there is an extra decompressed file in the current directory, move the file to /usr/local/, and change the folder name to mysql.
If mysql already exists under /usr/local/, please change the existing mysql file to another name, otherwise the subsequent steps may not be performed correctly.
Execute the command as follows:
[root@kaypc ~]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/
[root@kaypc ~]# cd /usr/local/
[root@kaypc local]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
If the mysql folder does not exist under /usr/local/ , directly execute the following command to achieve the above effect.
[root@kaypc /]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
2. Create a data directory under the /usr/local/mysql directory:
[root@kaypc ~]# mkdir /usr/local/mysql/data
3. Change the user groups, users, and permissions of all directories and folders under the mysql directory
[root@kaypc ~]# chown -R mysql:mysql /usr/local/mysql
[root@kaypc ~]# chmod -R 755 /usr/local/mysql
4. Compile, install and initialize mysql, be sure to remember the password at the end of the initialization output log (database administrator temporary password)
[root@kaypc ~]# cd /usr/local/mysql/bin
[root@kaypc bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
Supplementary Note:
During step 4, an error may occur.
When this problem occurs, first check whether the link library file is installed and use the command to check
[root@kaypc bin]# rpm -qa|grep libaio
After running the command, it is found that the link library file does not exist in the system.
Excuting an order:
[root@kaypc bin]# yum install libaio-devel.x86_64
[root@kaypc bin]# yum -y install numactl
After the execution is correct, re-execute the initialization command in step 4, and then proceed to step 5 after it is correct!
5. After running the initialization command successfully, the output log is as follows:
Record the string at the end of the log after root@localhost:, which is the temporary login password of the mysql administrator
6. Edit the configuration file my.cnf and add the configuration as follows
The file is cleared of the original, and all are added including [mysqld]
Order:
[root@localhost bin]# vi /etc/my.cnf
A capital I enters edit mode.
[mysqld]
datadir=/usr/local/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
character_set_server=utf8
After editing, press the ESC key, wq! to force save and exit.
lower_case_table_names
: Whether it is case-sensitive, 1 means the table name is lowercase when storing, and it is not case-sensitive when operating; 0 means case-sensitive; it cannot be set dynamically, and it must be restarted to take effect after modification: : Set the default character set of the database, if not character_set_server
set The default is latin1 innodb_file_per_table
: Whether to store the data of each table separately, 1 means separate storage; 0 means close the independent table space, you can view the difference in file structure by viewing the data directory;
7. Test start the mysql server
[root@kaypc bin]# /usr/local/mysql/support-files/mysql.server start
The following results are displayed, indicating that the database is installed and can be started normally
abnormal situation
If the following prompt message appears:
Starting MySQL... ERROR! The server quit without updating PID file
Check whether there are mysql and mysqld services, if they exist, end the process, and then re-execute the startup command
[root@kaypc bin]# ps -ef|grep mysql | grep -v grep
[root@kaypc bin]# ps -ef|grep mysqld | grep -v grep
End process: kill -9 PID
Start the service:
[root@kaypc bin]# /usr/local/mysql/support-files/mysql.server start
8. Add a soft connection and restart the mysql service
[root@kaypc bin]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@kaypc bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@kaypc bin]# service mysql restart
9. Log in to mysql and change the password (the password is the temporary password generated in step 5)
[root@kaypc bin]# mysql -u root -p
Note: When entering the password, there will be no display after Enter password. At this time, the input is actually successful. After entering the password, press Enter directly to enter the database.
If you have not saved and remembered the temporary password generated in step 5, the initial password is in the file /var/log/mysqld.log. Enter the command: grep 'temporary password' /var/log/mysqld.log to obtain the password directly.
(Note: The password is all characters after the colon!)
change Password:
mysql> set password for root@localhost = password('yourpass');
10. Open remote connection
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
11. Set the boot to start automatically
If the clock is still running in mysql, quit exits mysql
Copy the service file to init.d and rename it to mysql
[root@kaypc usr]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
grant executable permissions
[root@kaypc usr]# chmod +x /etc/init.d/mysqld
add service
[root@kaypc usr]# chkconfig --add mysqld
show service list
[root@kaypc usr]# chkconfig --list
test:
So far, the database installation of mysql5.7.24 version has been completed. The system is CentOS Linux release 7.8.2003 (Core)