centos啟動mysql
centos8里不需要安裝mariadb-server
1.在宿主機上安裝mariadb的客戶端軟件,獲得mysql命令
yum ?install ?mariadb
2.啟動mysql的容器
docker run --name sc-mysql-1 -e MYSQL_ROOT_PASSWORD='sc123456' -d -p 3306:3306 ?mysql:5.7.35
代碼如下:
[root@docker web]# docker run --name chaochao-mysql-1 -e MYSQL_ROOT_PASSWORD='123456' -d -p 3306:3306 ?mysql:5.7.35
?
fb2798a41de84218932556fce998fc86673e330e01d602911fc725ed3b7251fb
?
[root@docker web]# docker ps -a
?
CONTAINER ID ? IMAGE ? ? ? ? ? ? ? COMMAND ? ? ? ? ? ? ? ? ?CREATED ? ? ? ? ? ? STATUS ? ? ? ? ? ? ? ? ? ? ?PORTS ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?NAMES
?
fb2798a41de8 ? mysql:5.7.35 ? ? ? ?"docker-entrypoint.s…" ? 20 seconds ago ? ? ?Up 18 seconds ? ? ? ? ? ? ? 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp ? chaochao-mysql-1
3.去訪問(可以是其他的機器)
訪問其他機器:mysql -h ip -uroot -p密碼
-h 指定連接服務器的ip地址
注:若連不上,需要重啟docker服務
-
?
[root@docker web]# mysql -h 192.168.0.17 -uroot -p123456
?
Welcome to the MariaDB monitor. ?Commands end with ; or \g.
?
Your MySQL connection id is 2
?
Server version: 5.7.35 MySQL Community Server (GPL)
?
?
?
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
?
?
?
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
?
?
?
MySQL [(none)]> show databases; ?查看有哪些數據庫
?
+--------------------+
?
| Database ? ? ? ? ? |
?
+--------------------+
?
| information_schema |
?
| mysql ? ? ? ? ? ? ?|
?
| performance_schema |
?
| sys ? ? ? ? ? ? ? ?|
?
+--------------------+
?
4 rows in set (0.002 sec)
?
?
?
MySQL [(none)]> exit 退出
?
Bye