Linux manual installation MySQL5.7

1, download the tar package, where the use wget to download from the official website

https://dev.mysql.com/downloads/mysql/

2, installed to the mysql / usr / local / mysql

# Unzip

tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql

3, the new data directory

mkdir /usr/local/mysql/data

4, the new mysql user, user group mysql

# Mysql user group

groupadd mysql

# Mysql user

useradd mysql -g mysql

5, / usr / local / mysql belongs to the owner and group changed mysql

chown -R mysql.mysql /usr/local/mysql

6, configuration

/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data

If the following error:

2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-07-14 06:40:32 [ERROR]   Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2018-07-14 06:40:32 [ERROR]   Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
Use the following command (recall the data files generated by the above command contents deleted): / 
usr / local / MySQL / bin / MySQL --basedir mysqld --user = = / usr / local / MySQL / --datadir = / usr / local / mysql / data --initialize
If the following error:
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

Execute the following command:

yum -y install numactl

After the completion of the previous step is repeated to continue the installation (similar to the above content data file deleted):

/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
编辑/etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

7, open service

# Mysql join the service

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

# Boot from Kai

chkconfig mysql on

# Open

service mysql start

( Sometimes returns the following error:

1.service mysql start;

 报错:mysql is neither service nor target!?

2.systemctl start mysql:

 报错:sysemctl start  mysql : Failed to star mysql.service: Unit mysql.service failed to load: No such file ....)

Solution: Perform the following command

systemctl unmask mysql.service

service mysql start

8, set a password

# Log (canceled due /etc/my.cnf set up password authentication, so any password here)

/usr/local/mysql/bin/mysql -u root -p

# Mysql database operations

>>use mysql;

# change Password

>>update user set authentication_string=password('你的密码') where user='root';

>>flush privileges;

>>exit;

9, the skip-grant-tables /etc/my.cnf of deleted

10, login password again (do not know why not set a password if you can not operate the database again)

/usr/local/mysql/bin/mysql -u root -p

 >> ALTER USER 'root' @ 'localhost' IDENTIFIED BY 'modified password';

>>exit;

11, allow remote connections

/usr/local/mysql/bin/mysql -u root -p

>>use mysql;

>>update user set host='%' where user = 'root';

>>flush privileges;

>>eixt;

If not, directly off linux firewall. This still does not work, check the server stack stack rules.

12, add shortcuts

ln -s /usr/local/mysql/bin/mysql /usr/bin

Guess you like

Origin www.cnblogs.com/kaspar/p/11453699.html