Summary of mysql8.x single machine installation

Posted by shellyrobson on Thu, 12 Dec 2019 15:22:48 +0100

1. Download the mysql installation package, extract the installation file, and change the name to mysql

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz

2. Create data directory in mysql folder

mkdir data

3. Create mysql user group and mysql user

groupadd mysql

useradd -g mysql mysql

4. Change mysql directory permission

chown -R mysql:mysql /opt/tools/mysql

5. Create mysql configuration file my.cnf

vim /etc/my.cnf

//The contents of the document are as follows
[client]
port=3306
socket=/opt/tools/mysql/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/opt/tools/mysql/mysql.sock
basedir=/opt/tools/mysql
datadir=/opt/tools/mysql/data
log-error=/opt/tools/mysql/logs/error.log

6. Initialize mysql

bin/mysqld --initialize --user=mysql --basedir=/opt/tools/mysql/ --datadir=/opt/tools/mysql/data/

7. Start mysql service

support-files/mysql.server start

Problems encountered during installation:

1. After starting mysql, you can't log in without a password, and the root user can't log in without a blank password. After starting MySQL service normally, you can't log in by tapping the root account and password in Linux.

Be careful: skip-grant-table Start failed to execute ALTER user 'root'@'localhost' IDENTIFIED BY '123456'

1,stay/etc/my.cnf Add to profile skip-grant-table,Password verification is blocked
vim /etc/my.cnf  

2,stay [mysqld]Finally add skip-grant-tables Statement and keep the exit file

3,restart mysql service
service mysqld restart

4,Log in after startup mysql
mysql -u root -p  

5,View user list
select host, user, authentication_string, plugin from user;
host: Allow users to log in ip'position'%Indicates that it can be remote;
user:User name of the current database;
authentication_string: User password; on mysql 5.7.9 It's abandoned later password Field and password()function

6,Change Password,If current root user authentication_string There is content under the field, set it to empty first
use mysql;  
update user set authentication_string='' where user='root';

7,Sign out mysql, delete/etc/my.cnf The last skip-grant-tables

8,restart mysql service

9,Sign in mysql terminal,Prompt password to directly type Enter
mysql -uroot 

10,Change Password
ALTER user 'root'@'localhost' IDENTIFIED BY '123456'

 

2. MySQL 1130 error, unable to connect remotely

Error: Error 1130: host 'xxx. XXX. XXX. Xxx' is not allowed to connect to this MySQL service

Error 1130: host 192.168.1.3 'is not allowed to connect to thissysql service

Reason: the connected data cannot be accessed by using xxx.xxx.xxx.xxx, only localhost is allowed;

1,Sign in mysql
mysql -u root -p 123456

use mysql;

select 'host' from user where user='root';

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

flush privileges;

select 'host' from user where user='root';

//After running, connect the test again. If not, restart the mysql service

 

3. 1251 error in Navicat connecting Mysql

Because in the version before mysql8, the encryption rule is MySQL native password, and after mysql8, the encryption rule is caching Sha2 password

1,Modify encryption rules
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;

2,Update the user's password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

3,Refresh authority 
FLUSH PRIVILEGES; 

Topics: Database MySQL Linux vim socket