run --name hi-mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql 映射端口: run --name hi-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
进入容器:
1
docker exec -it hi-mysql bash
连接 mysql
容器内:
1
mysql -uroot -p123456
宿主机: 先安装 mysql 客户端:
1
apt install mysql-client-core-5.7
连接容器:
1
mysql -h 127.0.0.1 -P 3306 -u root -p123456
远程:
1
mysql -h 120.97.3.9 -P 3305 -u root -p123456
操作
连接成功提示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.7.20 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>后即可输入sql语句。sql语句使用分号“;”作为结束符号。
退出mysql命令行:
1
exit
查看数据库:
1 2 3 4 5 6 7 8 9 10
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)