preface
Recently the project went live and started to be tested by users. Get down a lot of servers, naturally want to install a mysql server. Think of the majority of bloggers should encounter how to install mysql problems, this share, to give you a guide to install. For everyone later installation, improve efficiency, instantaneous completion.
The preparatory work
Mysql5.7.25 tar package Baidu download it by yourself! Leave a message for me!
Installation steps
Check whether you have an older version of mysql
Check for older versions
rpm -qa | grep mysql
Copy the code
If no information is displayed, the machine does not have an older version of mysql. If so, the mysql version is displayed. Like this
Mysql - libs - 5.1.52-1. El6_0. 1. X86_64Copy the code
If so, we want to uninstall it, the uninstall command is as follows:
rpm -eMysql - libs - 5.1.52-1. El6_0. 1. X86_64 & emsp;   // Common delete mode RPM-e-- nodeps mysql - libs - 5.1.52-1. El6_0. 1. X86_64 & emsp;   // Forcible deletion mode. If the preceding command is used to delete dependent files, you can use this command to forcibly delete themCopy the code
After checking mysql, check if there is an older version of mariadb database, if so, delete it again. The steps are similar to those above.
rpm -qa | grep mariadb
Copy the code
rpm -e-- nodeps mariadb - libs - 5.5.56-2. El7. X86_64Copy the code
upload
/data/mysql/mysql5.7.25 / mysql5.7.25 / mysql5.7.25 / mysql5.7.25 / mysql5.7.25 / mysql5.7.25 / mysql5.7.25 The following directories, if not, need to be set up first. Unpack the tar packages
cd/ opt/mysql tar ZXVF mysql - 5.7.25 - Linux - glibc2.12 - x86_64. Tar. GzCopy the code
Rename the decompressed folder to facilitate future operations.
Mysql - 5.7.25 - Linux - mv glibc2.12 x86_64 mysql -- 5.7.25Copy the code
Add mysql groups and users to the system
Check to see if it already exists in the system.
cat /etc/group | grep mysql
Similar to #
mysql:x:490:
cat /etc/passwd | grep mysql
Similar to #
mysql:x:496:490::/home/mysql:/bin/bash
Copy the code
If no result is found in the cat command, create users and groups.
groupadd mysql
useradd -r -g mysql mysql
The #useradd -r parameter indicates that the mysql user is a system user and cannot be used to log in to the system
Copy the code
Installing the Database
Create data directory
cdMysql - 5.7.25 mkdir dataCopy the code
Change the owner and group of /opt/mysql/mysql-5.7.25 to mysql
Chown -r mysql. Mysql/opt/mysql/mysql - 5.7.25Copy the code
Create my_default. CNF in /opt/mysql/mysql-5.7.25/support-files and add the following content to the directory.
[mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir = /opt/mysql/mysql-5.7.25 datadir = /opt/mysql/mysql-5.7.25/data port = 3306 socket = / TMP /mysql.sock character-set-server=utf8log-error = /opt/mysql/ mysqld-5.7.25 /data/ mysqlD. log pid-file = /opt/mysql/ mysqlD-5.7.25 /data/mysqld.pidCopy the code
Copy the file to etc and select overwrite if it already exists.
cp support-files/my_default.cnf /etc/my.cnf
Copy the code
Initialize the mysql database
cd/opt/mysql/ mysqld --initialize --user=mysql --basedir=/opt/mysql/mysql-5.7.25/ - the datadir = / opt/mysql/mysql - 5.7.25 / data /Copy the code
After the initialization is complete, view logs
/ opt/mysql/mysql - 5.7.25 / data/mysqld logCopy the code
Temporary passwords can be seen in logs
[Note] A temporary password is generated forroot@localhost: ee4fa12as! daCopy the code
Place the startup script in the boot initialization directory
cp support-files/mysql.server /etc/init.d/mysql
Copy the code
Start the mysql service
service mysql start
Copy the code
Log in to mysql with the initialization password that we see in the log
cd/opt/mysql/mysql-5.7.25./bin/mysql -u root -pCopy the code
Change the password
mysql> set password=password('123456');
mysql> grant all privileges on *.* to root@The '%' identified by '123456';
mysql> flush privileges;
Copy the code
Example Add the remote access permission.
mysql> use mysql;
mysql> update user set host=The '%' where user = 'root';
mysql> flush privileges;
Copy the code
Restart the mysql
service mysql stop
service mysql start
Copy the code
or
service mysql restart
Copy the code
conclusion
Mysql has been successfully installed. /etc/init.d/basedir/basedir/basedir/basedir/basedir/basedir/basedir/basedir/basedir/basedir/basedir/basedir/basedir Restart.