docker中安装mysql数据库 - 炫Q香蕉派

docker中安装mysql数据库

首先创建实例
docker run -ti -h mysql --name mysql3307 -p 23307:3307 ubuntu:14.04
然后更新
apt-get update
apt-get install mysql-server
修改mysql端口3307
vi /etc/mysql/my.cnf
配置文件新位置/etc/mysql/mysql.conf.d/mysqld.cnf
有两个地方3306改成3307
注释掉bind-address = 127.0.0.1
重起服务
service mysql restart
登录到mysql
mysql -u root -p
create database testDB DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
CREATE USER 'test' IDENTIFIED BY '1234';
grant all privileges on testDB.* to test@"%" identified by '1234' with grant option;
flush privileges;
exit

然后用客户端访问23307端口就可以了,账号test,密码1234,关掉ssh也不受影响。

再建一个库
docker attach mysql3307
mysql -u root -p
create database newDB DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
grant all privileges on newDB.* to test@"%" identified by '1234' with grant option;
flush privileges;
exit

标签: none

添加新评论