海外主机测评

您现在的位置是:首页 > 服务器 > 正文

服务器

使用docker启动mysql

cds8202023-03-07服务器88
centos启动mysqlcentos8里不需要安装mariadb-server1.在宿主机上安装mariadb的客户端软件,获得mysql命令yum install mariadb2.

centos启动mysql

centos8里不需要安装mariadb-server

1.在宿主机上安装mariadb的客户端软件,获得mysql命令

yum  install  mariadb

2.启动mysql的

docker run --name sc-mysql-1 -e MYSQL_ROOT_PSWORD='sc123456' -d -p 3306:3306  mysql:5.7.35

代码如下:

[ web]# docker run --name chaochao-mysql-1 -e MYSQL_ROOT_PASSWORD='123456' -d -p 3306:3306  mysql:5.7.35
 
fb2798a41de84218932556fce998fc86673e330e01d602911fc725ed3b7251fb
 
[ 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服务

  1.  
[ web]# mysql -h 192.168.0.17 -uroot -p123456
 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
 
Your 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

文章链接: https:///17960.html

文章标题:

文章版权:所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!

发表评论

评论列表

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~