docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
–name 后面的是docker容器名
-e MYSQL_ROOT_PASSWORD 是设置mysql的root账号密码
-d mysql 是你的镜像标签
启动成功后
[root@iZttsn6fen661yZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e661357b4012 mysql "docker-entrypoint..." 3 seconds ago Up 2 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
[root@iZttsn6fen661yZ ~]# docker exec --ti e661357b4012 bash
unknown flag: --ti
See 'docker exec --help'.
[root@iZttsn6fen661yZ ~]#
[root@iZttsn6fen661yZ ~]#
[root@iZttsn6fen661yZ ~]# docker exec -ti e661357b4012 bash
root@e661357b4012:/#
root@e661357b4012:/#
root@e661357b4012:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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> create database test;
Query OK, 1 row affected (0.05 sec)
mysql> use test;
Database changed
mysql> create table user(id VARCHAR(20),name VARCHAR(25),age INT(4));
Query OK, 0 rows affected (0.11 sec)
mysql>