本节会用到的Docker命令如下:
docker images 查看mysql镜像id docker run -d -p xxxxxxxxxxxxxxx/zhufc/mysql:v2 通过镜像生成 启动容器 4406映射端口 3306是mysql默认端口 docker ps -a 查看生成的容器 docker ps docker restart 容器id docker stop 容器id 停止容器 docker rm 容器id 删除容器id docker exec -it {mysql容器id} bash 进入指定容器 ps -ef | grep mysql 查看mysql服务 容器启动 mysql服务启动 绑定的
1、拉取Mysql镜像文件。
2、使用docker images查看下载的镜像文件
3、通过镜像生成容器
查看生成的容器:
4、停止容器,创建容器,查看容器
5、正在运行的容器无法删除,先停止掉,在删除容器
6、进入指定的容器 docker exec -it 要进入的容器ID
7、ps -ef | grep mysql 查看mysql服务,如果容器启动,则mysql服务启动 ,容器绑定mysql绑定
8、进入Mysql数据库修改配置文件
或者生效profile文件。
vim /etc/profile/ source /etc/profile 设置服务生效 mysql -u root -p000000 进入数据库
数据库的一些操作:
show databases; 查看库名
use mysql; 初始化数据库
drop api; 删除api数据库
create database api;设置api数据库
启动小幺鸡项目数据库:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | aiopms | | api | | mysql | | performance_schema | | renren_security | | test | +--------------------+ 7 rows in set (0.00 sec) mysql> show tables; +------------------+ | Tables_in_api | +------------------+ | attach | | doc | | doc_history | | email_token | | find_password | | interface | | interface_folder | | module | | project | | project_global | | project_log | | project_user | | share | | sys | | team | | team_user | | user | | user_third | +------------------+ 18 rows in set (0.00 sec) mysql> mysql> mysql> mysql> mysql> mysql> mysql> mysql> mysql> mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | aiopms | | api | | mysql | | performance_schema | | renren_security | | test | +--------------------+ 7 rows in set (0.02 sec) mysql> use api; Database changed mysql> show tables; +------------------+ | Tables_in_api | +------------------+ | attach | | doc | | doc_history | | email_token | | find_password | | interface | | interface_folder | | module | | project | | project_global | | project_log | | project_user | | share | | sys | | team | | team_user | | user | | user_third | +------------------+ 18 rows in set (0.00 sec) mysql> source /usr/xiaoyaoji.sql Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.03 sec) Query OK, 0 rows affected (0.14 sec) Query OK, 0 rows affected (0.04 sec) Query OK, 0 rows affected (0.21 sec) Query OK, 0 rows affected (0.03 sec) Query OK, 0 rows affected (0.11 sec) Query OK, 0 rows affected (0.04 sec) Query OK, 0 rows affected (0.10 sec) Query OK, 0 rows affected (0.04 sec) Query OK, 0 rows affected (0.12 sec) Query OK, 0 rows affected (0.03 sec) Query OK, 0 rows affected (0.15 sec) Query OK, 0 rows affected (0.03 sec) Query OK, 0 rows affected (0.18 sec) Query OK, 0 rows affected (0.04 sec) Query OK, 0 rows affected (0.18 sec) Query OK, 0 rows affected (0.05 sec) Query OK, 0 rows affected (0.12 sec) Query OK, 0 rows affected (0.03 sec) Query OK, 0 rows affected (0.11 sec) Query OK, 0 rows affected (0.05 sec) Query OK, 0 rows affected (0.12 sec) Query OK, 0 rows affected (0.02 sec) Query OK, 0 rows affected (0.17 sec) Query OK, 0 rows affected (0.03 sec) Query OK, 0 rows affected (0.11 sec) Query OK, 0 rows affected (0.03 sec) Query OK, 0 rows affected (0.11 sec) Query OK, 0 rows affected (0.04 sec) Query OK, 0 rows affected (0.11 sec) Query OK, 0 rows affected (0.06 sec) Query OK, 0 rows affected (0.14 sec) Query OK, 0 rows affected (0.10 sec) Query OK, 0 rows affected (0.23 sec) Query OK, 0 rows affected (0.04 sec) Query OK, 0 rows affected (0.19 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) mysql>
mysql>
使用mysql数据库,授权执行:
grant all on *.* to 'root'@'192.168.3.111' identified by '000000'; --192.168.1.6为自己虚拟机ip grant all on *.* to 'root'@'172.17.0.2' identified by '000000'; -- ip 随机分配 默认不需要管 grant all privileges on *.* to root@'%' identified by "000000"; -- root FLUSH PRIVILEGES; # 刷新权限
退出到ubuntu界面:
下载Navtice数据库,输入ip、账号、密码,测试连接。
在mysql数据库下面有个user表,删除该表下面的所有密码为空的用户。
到此,mysql数据库的服务配置完成。