1.

It took a long time to install MySQL8 on Linux(virtual machine), and I had a lot of problems, so I wanted to document the installation steps for reference next time. The MySQL package is mysql-8.0.19-linux-glibc2.12-x86_64.tar.

2. Specific steps

1. Decompress the /usr/local folder and rename the folder to mysql

Mysql-8.0.19-linux-glibc2.12-x86_64. tar = mysql-8.0.19-linux-glibc2.12-x86_64Copy the code

2. Go to the mysql folder and create a new folder named data

mkdir data
Copy the code

Create users and groups, and change the owner of the mysql directory

groupadd mysql 
useradd -r -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
Copy the code

4. Modify the /etc/my. CNF file. If no, manually create the file

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
Copy the code

5. Go to /usr/local/mysql.bin to initialize the database and save the temporary password

./mysqld --initialize --user=mysql
Copy the code

6. Start MySQL in background

./mysqld --user=mysql &
Copy the code

7. Use a temporary password to log in

./mysql -uroot -p
Copy the code

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/ TMP /mysql.sock’ (2)

Solution: Set up a soft link to the automatically generated mysql.sock

ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock
Copy the code

8. After login, change the password

alter user `root`@`localhost` identified by '123456';
Copy the code

9. Create a user and modify permissions for access from other machines

create user `root`@`%` identified by '123456';

-- Grant permission to user root who logs in to localhost
grant all privileges on *.* to `root`@`localhost`;

-- Grant permissions to root users who log in from any machine
grant all privileges on *.* to `root`@`%`;

flush privileges;
Copy the code

10. Open port 3306 for the firewall

firewall-cmd --zone=public --add-port=3306/tcp --permanent
Copy the code

3. Related links

  • Official Download address
  • The resources