Mysql5.7 Linux compilation and installation tutorial



Reproduced from:

1. System agreement

Installation file download directory: / data / software
MySQL directory installation location: / usr / local / MySQL
Database save location: / usr / local / MySQL / data
Log save location: / TMP / MySQL_ error.log

2. Download MySQL (the pre compiled two process MySQL installation package is downloaded here)

On the official website:  In, select the following version of Mysql to download:

Choose 32 or 64 bit according to the version of your system. Here I choose 64 bit system

Suggestion: use Xunlei download on windows, which is very fast, and then upload it to / usr / local / SRC directory with tool (xftp);

Or download it directly to the server
Copy the download address WGet + address (download to the current directory by default, and save it in your own directory)

cd /usr/local/src

3. After downloading, unzip it

tar zxvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

4. Move to the unzipped folder/usr/local/mysql

mv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/mysql
MKDIR data // create a new folder
mkdir mysql-files
Groupadd mysql. // create a new MySQL group
useradd -g mysql mysql
Chown - R MySQL: MySQL / usr / local / MySQL // modify the MySQL installation directory and data center permissions:
Cat / etc / passwd // view user and group information: View user list
Cat / etc / group // view the user group list
Chown - R mysql. // change the directory owner under / usr / local / MySQL directory
chgrp -R mysql .

5. Modify MySQL configuration file

vim /etc/my.cnf

port = 3306

mkdir /var/lib/mysql
chmod 777 /var/lib/mysql

6. Configure parameters and obtain password command:

Execute initialize database command:

bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

If an error is reported and the plug-in is missing, go to Baidu libnuma. So. 1 and find that numactl is missing. Download and install it  yum -y install numactl  Then execute the above initialization database command

After successful startup, check that there is data in the data file directory
ll data

Note here that the generated temporary password is recorded, as at the end of the above

If the password is not displayed, use the following command to view the password:

cat /tmp/mysql_error.log

bin/mysql_ssl_rsa_setup --datadir=/usr/local/data/mysql/ / setting SSL does not need to be executed

7. Start MySQL server mysqld

[email protected]:~# /usr/local/mysql/support-files/mysql.server start
Starting MySQL
.Logging to '/tmp/mysql_error.log'.
. ok

The above startup succeeded

There are three possible errors during installation:

a. The MySQL service has been started. If you start it again, an error will be reported

If an error is reported as shown in the figure above, perform the following operations, kill the process, execute again, and restart

ps -aux|grep mysql
kill -9 1512
/usr/local/mysql/support-files start`

b. If you still can’t start, delete the data folder and rebuild it,

cd /usr/local/mysql
        rm -rf /data
     MKDIR data // change the permissions of the new data folder to group	
	Chown - R MySQL: MySQL / usr / local / MySQL / data // change permission command	
	Bin / mysqld -- initialize -- user = MySQL -- basedir = / usr / local / MySQL -- dataDir = / usr / local / MySQL / data // initialize again
        cat /tmp/mysql_ error.log 	// Check the password
	. / support files / MySQL. Server start // restart and it will be OK

c. If you still can’t, install it/usr/local/mysqlAfter deleting the folder, unzip the MySQL file in / user / local / SRC and copy it to the / usr / local folder,

Delete / etc / my.cnf and rebuild it,
  Check if there is a process, kill the MySQL process,   
 Repeat the method above B

9. After setting the environment variable, reload it to take effect

Edit profile file
vim /etc/profile

export PATH=$PATH:/usr/local/mysql/bin


echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
/Usr / local / MySQL / support files // if it is Ubuntu, add this sentence
Source / etc / profile // refresh takes effect

Connect to database

MySQL - uroot - P password // Connect to MySQL
If the following error is prompted: connect with Navicat, and then change the password
Your password has expired. To log in you must change it using a client that supports expired passwords

alter user 'root'@'localhost' identified by ' [email protected] '; // modify the account and password

use mysql
Create user username @ '%' identified by 'password'// Create account haiama user name
Grant all privileges on *. * to user name @ '%' with grant option// to grant authorization
select version(); // View version

Quit / exit // exit

Set startup:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysqld 
chkconfig mysql on

service mysql start //centos
mysql.server start //ubuntu

service mysql restart //centos
mysql.server restart //ubuntu

stop it:
service mysql stop //centos
mysql.server stop //ubuntu

Look at the startup log:
cat mysql_error.log

View MySQL status:
service mysql status

Stop MySQL service
service mysql stop

Or kill the process:
killall -9 mysql

If killall is not installed, you can install it using Yum or up2date
yum provides killall
find outpsmisc-22.20-11.el7.x86_64
yum -y install psmisc-22.20-11.el7.x86_64
killall -9 mysql

Forget the password and initialize the password (you need to back up the data in advance. After resetting, the data will be gone)

Kill - 9 MySQL // stop the MySQL software
Pkill - 9 MySQL // the same as the above command stops the MySQL software
RM -rf / usr / local / MySQL / data // delete the data directory
MKDIR data // create a new data folder
Chown - R mysql.mysql / usr / local / MySQL // add permission
Bin / mysqld -- initialize -- user = MySQL -- basedir = / usr / local / MySQL -- dataDir = / usr / local / MySQL / data // initialize the password and save it
cat /tmp/mysql_ Error.log // view the password
mysql_ ssl_ rsa_ Setup // set SSL
Service mysql start // start
MySQL - uroot - P password // login
alter user 'root'@'localhost' identified by 'whm****@**.com'; // modify the account password and change the root password. It needs numbers, uppercase letters, lowercase letters and special symbols
flush privileges;

1. Modify / etc / my.cnf and add a line under the [mysqld] section: skip grant tables = 1
This line of configuration allows mysqld to start without verifying the password

vim /etc/my.conf
Add one line:skip-grant-tables=1

2. Restart mysqld service:
/usr/local/mysql/support-files/mysql.server restart

3. Log in to using root  mysql
mysql -u root

alter user 'root'@'localhost' identified by 'whm****@***.com'; // modify the account and password

Note: if the remote tool cannot be connected, please use  iptables -F  Command to clear firewall rules

MySQL extension

Changing the root password requires numbers, uppercase letters, lowercase letters, and special symbols

Example: your new password is [email protected]! XLD

#Set password = password ('your new password ');
#If the above method doesn't work, just use the following one
Alter user user() identified by 'your new password';
#Set password never to expire
#Refresh MySQL system permission related tables
flush privileges;

According to personal needs, set the database user to be accessible under all IP addresses and locally. The following is a demonstration with root user

Grant all privileges on *. * to root @ "%" identified by "your password" with grant option; // give all IP addresses permission
Grant all privileges on *. * to root @ "localhost" identified by "your password" with grant option;
grant all privileges on *.* to 'root'@'' identified by '12345' with grant option;  // Give permission to the specified IP address
grant all privileges on *.* to 'root'@'113.46.*.*' identified by '12345' with grant option;  // Give permission to the specified IP segment
flush privileges;

Note: if the remote tool cannot be connected, use the iptables – f command to clear the firewall rules

New user

CREATE USER 'xld_ Test '@'% 'identified by' your password ';

User authorization

Add user permissions:  GRANT ALL ON databasename.tablename TO 'xld_test'@'%';
Revoke user rights:  REVOKE ALL ON databasename.tablename TO 'xld_test'@'%';
Delete users and permissions:drop user 'xld_test'@'%';