# 使用docker启动mysql

> 来源：梦飞idc云平台 | 原文：https://www.mfisp.com/15776.html | 发布：2023-01-18 | 更新：2023-01-18 | 分类：建站教程、投稿分享

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`

 

``

 

`**3.****去访问（**可以是其他的机器）`

 

``

 

`访问其他机器：mysql -h ip -uroot -p密码`

 

``

 

`-h 指定连接服务器的ip地址`

 

``

 

`注：若连不上，需要重启docker服务`

 

``

 

```

```

 

``

 
 
1. [root@docker web]# mysql -h 192.168.0.17 -uroot -p123456 
1.  
1. Welcome to the MariaDB monitor. Commands end with ; or \g. 
1.  
1. Your MySQL connection id is 2 
1.  
1. Server version: 5.7.35 MySQL Community Server (GPL) 
1.  
1.  
1.  
1. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 
1.  
1.  
1.  
1. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
1.  
1.  
1.  
1. MySQL [(none)]> show databases; 查看有哪些数据库 
1.  
1. +--------------------+ 
1.  
1. | Database | 
1.  
1. +--------------------+ 
1.  
1. | information_schema | 
1.  
1. | mysql | 
1.  
1. | performance_schema | 
1.  
1. | sys | 
1.  
1. +--------------------+ 
1.  
1. 4 rows in set (0.002 sec) 
1.  
1.  
1.  
1. MySQL [(none)]> exit 退出 
1.  
1. Bye 

 

``

 

```

```

 

``

  

``

---
本页由 梦飞idc云平台（https://www.mfisp.com）提供。站点导航见 https://www.mfisp.com/llms.txt
