标签:repos centos7 查询语句 repo select get current 个数 ati
docker安装mysql环境非常方便,简单的几步操作就可以了
先拉取mysql的镜像,可以在docker的镜像仓库找到不同TAG标签的版本https://hub.docker.com/_/mysql?tab=tags
我这里选择mysql:5.7标签
[root@yoyo ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
fc7181108d40: Already exists
787a24c80112: Already exists
a08cb039d3cd: Already exists
4f7d35eb5394: Already exists
5aa21f895d95: Already exists
a742e211b7a2: Pull complete
0163805ad937: Pull complete
62d0ebcbfc71: Pull complete
559856d01c93: Pull complete
c849d5f46e83: Pull complete
f114c210789a: Pull complete
Digest: sha256:c3594c6528b31c6222ba426d836600abd45f554d078ef661d3c882604c70ad0a
Status: Downloaded newer image for mysql:5.7
docker images查看已经下载成功
REPOSITORY TAG IMAGE ID CREATED SIZE
centos v7.5 254d4dfe9df7 3 days ago 200MB
mysql 5.7 a1aa4f76fab9 2 weeks ago 373MB
centos/python-36-centos7 latest b8d15efaa8ec 2 months ago 651MB
centos centos7.5.1804 cf49811e3cdb 3 months ago 200MB
ubuntu 15.10 9b9cb95443b5 2 years ago 137MB
training/webapp latest 6fae60ef3446 4 years ago 349MB
[root@yoyo ~]#
创建mysql目录,用于存放mysql相关配置及数据
mkdir -p ~/yoyo/mysql/conf ~/yoyo/mysql/data ~/yoyo/mysql/logs
创建完成后,在当前用户的home目录(root用户在root目录),会有三个文件夹
[root@yoyo ~]# mkdir -p ~/yoyo/mysql/conf ~/yoyo/mysql/data ~/yoyo/mysql/logs
[root@yoyo mysql]# ll ~/yoyo/mysql
total 12
drwxr-xr-x 2 root root 4096 Jun 30 10:31 conf
drwxr-xr-x 2 root root 4096 Jun 30 10:31 data
drwxr-xr-x 2 root root 4096 Jun 30 10:31 logs
docker run -p 3309:3306 --name yoyomysql -v ~/yoyo/mysql/conf:/etc/mysql/conf.d -v ~/yoyo/mysql/logs:/logs -v ~/yoyo/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
命令说明:
启动完成后,查看运行状态
[root@yoyo mysql]# docker run -p 3308:3306 --name yoyomysql -v ~/yoyo/mysql/conf:/etc/mysql/conf.d -v ~/yoyo/mysql/logs:/logs -v ~/yoyo/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
581137afbd3ba22dc02bf89d3ec1afb6e51d55eed0d99a3a4a979bdee8d5de4a
[root@yoyo ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
581137afbd3b mysql:5.7 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 33060/tcp, 0.0.0.0:3309->3306/tcp yoyomysql
查看~/yoyo/mysql/data目录会看到有数据
[root@yoyo ~]# ll ~/yoyo/mysql/data/
total 188476
-rw-r----- 1 polkitd ssh_keys 56 Jun 30 10:38 auto.cnf
-rw------- 1 polkitd ssh_keys 1679 Jun 30 10:38 ca-key.pem
-rw-r--r-- 1 polkitd ssh_keys 1107 Jun 30 10:38 ca.pem
-rw-r--r-- 1 polkitd ssh_keys 1107 Jun 30 10:38 client-cert.pem
-rw------- 1 polkitd ssh_keys 1675 Jun 30 10:38 client-key.pem
-rw-r----- 1 polkitd ssh_keys 1340 Jun 30 10:38 ib_buffer_pool
-rw-r----- 1 polkitd ssh_keys 79691776 Jun 30 10:38 ibdata1
-rw-r----- 1 polkitd ssh_keys 50331648 Jun 30 10:38 ib_logfile0
-rw-r----- 1 polkitd ssh_keys 50331648 Jun 30 10:38 ib_logfile1
-rw-r----- 1 polkitd ssh_keys 12582912 Jun 30 10:38 ibtmp1
drwxr-x--- 2 polkitd ssh_keys 4096 Jun 30 10:38 mysql
drwxr-x--- 2 polkitd ssh_keys 4096 Jun 30 10:38 performance_schema
-rw------- 1 polkitd ssh_keys 1679 Jun 30 10:38 private_key.pem
-rw-r--r-- 1 polkitd ssh_keys 451 Jun 30 10:38 public_key.pem
-rw-r--r-- 1 polkitd ssh_keys 1107 Jun 30 10:38 server-cert.pem
-rw------- 1 polkitd ssh_keys 1675 Jun 30 10:38 server-key.pem
drwxr-x--- 2 polkitd ssh_keys 12288 Jun 30 10:38 sys
输入docker exec -it mysql bash进入容器bash,接着输入mysql -uroot -p输入root用户密码123456进入mysql
[root@yoyo data]# docker exec -i -t yoyomysql bash
root@581137afbd3b:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
进入mysql之后所有指令结尾都需要 ;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host, user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
4 rows in set (0.00 sec)
mysql> exit
Bye
root@581137afbd3b:/# exit
exit
退出mysql和容器用exit
标签:repos centos7 查询语句 repo select get current 个数 ati
原文地址:https://www.cnblogs.com/yoyoketang/p/11108971.html