centos7 docker install mysql8.0.22

1. Pull the mysql image (the latest image is pulled by default) 8.0.22

docker pull mysql:8.0.22

2. Create persistent mysql data and mysql.cnf on the host machine (directory customization, my.cnf does not need to write anything, according to personal preference)


mkdir /web/mysql-data/cnf
mkdir /web/mysql-data/data
vi /web/mysql-data/cnf/mysql.cnf

3. Add operation permissions

chmod 777 /usr/local/mysqlData/test/data
    备注:挂载时权限验证(操作权限)

4. Run the mirror image, set the initial password, the mapping between the local machine and the docker port, and mount the local data disk ( start the msyql service )

docker run -itd -p 3306:3306 --name mysql -v /web/mysql-data/cnf -v /web/mysql-data/data:/var/lib/mysql -v /web/mysql-data/mysql-files:/var/lib/mysql-files/ -e MYSQL_ROOT_PASSWORD=root mysql:8.0.22

 5. Enter the test_mysql container

 6. Since the password algorithm has been modified in versions above Mysql5.6, the password algorithm needs to be updated here to facilitate the use of Navicat connections (note, here I changed the password to "123456")

mysql> grant all PRIVILEGES on *.* to root@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.01 sec)
 
mysql> ALTER user 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.11 sec)
 
mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.11 sec)
 
mysql>  FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

 7. Use navicat to connect to mysql, as shown in the figure:

 

Guess you like

Origin blog.csdn.net/qq_25062671/article/details/120964131