MySQL installation process and those pits encountered

This article is based on Centos 6.5 and MySQL 5.7.22

1. Completely uninstall the MySQL service installed before

1. Stop the MySQL service

# service mysqld stop

2. Uninstall the MySQL service

View installed services

# rpm -qa | grep mysql

Uninstall installed MySQL services one by one

# rpm -e --nodeps mysql-community-server-5.7.22-1.el6.x86_64

3. Delete the installation files

Find installed MySQL file directory by name

# find / -name mysql

Delete file directories one by one

 # rm -rf /usr/share/mysql

2. Install MySQL in yum mode

1. Download and install the MySQL service yum installation dependency file

The first pit appeared, and it was downloaded directly from the official website through wget, so the rpm file had to be downloaded by windows and uploaded to the linux system through xftp.

mysql57-community-release-el6-11.noarch.rpm

2. Install yum dependency files

# yum install -y mysql57-community-release-el6-11.noarch.rpm

3. Install MySQL service

# yum install -y mysql-server mysql mysql-devel

4. Start the MySQL service in normal mode and initialize the database

The second pit appears, start the MySQL service in safe mode without initializing the database, set the password, and you will find that the database mysql does not exist

// 启动mysql服务进行数据库初始化
# service mysqld start
// 为了下一步操作,停止mysql服务
# service mysqld stop

5. Start the MySQL service in safe mode and set the login password

The third pit appeared. MySQL 5.7 strictly checks the password. It is recommended that the password contain uppercase and lowercase letters, numbers and special characters.

// 安全模式启动mysql
# mysqld_safe --skip-grant-tables&
// 免密码登录
# mysql -uroot -p

The fourth pit appeared, MySQL changed the name of the password field, no longer password but authentication_string

// 更改登录密码
> update mysql.user set authentication_string = password('********') where User = 'root' and Host = 'localhost';
// 刷新权限
> flush privileges;
// 退出
> quit

Restart the MySQL service and log in with the password set above

# servcie mysqld restart
# mysql -uroot -p
> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

There is no problem when logging in, but the database cannot be operated, and the above error is reported. This is the fifth pit, and the password needs to be reset.

// 此处注意要和上面的密码保持一致
> set password for 'root'@'localhost' = password('********');
> flush privileges;

Log in to the system again to perform normal database operations.

3. MySQL setup startup and remote login

1. Set boot up

# chkconfig mysqld on

2. Log in to MySQL service locally and set up remote login

# mysql -uroot -p
> update mysql.user set Host = '%' where User = 'root'
> flush privileges

Don't forget to open port 3306 in your firewall.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325683324&siteId=291194637