Ubuntu下安装MySQL
Ubuntu 14.04
安装必要的软件
1 2 3 |
sudo apt-get install mysql-server #修改root密码 mysqladmin -uroot -p原密码 password 新密码 |
注意,如果下载tar.gz的压缩包,需要手工进行数据库的初始化:
1 |
"scripts"/mysql_install_db --user=mysql --basedir=/var/mysql/ --datadir=/var/mysql/data/ --defaults-file=/path-to/my.cnf |
修改配置文件
1 2 |
sudo vi /etc/mysql/my.cnf #修改监听地址为:0.0.0.0 |
创建用户并授权
1 2 3 4 5 6 7 8 9 10 |
DB_ROOT_PSWD=root DB_USER=user DB_PSWD=pswd bin/mysql -uroot -p$DB_ROOT_PSWD <<InitialSQL CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PSWD'; GRANT ALL PRIVILEGES ON *.* TO '$DB_USER'@'localhost' WITH GRANT OPTION; CREATE USER '$DB_USER'@'%' IDENTIFIED BY '$DB_PSWD'; GRANT ALL PRIVILEGES ON *.* TO '$DB_USER'@'%' WITH GRANT OPTION; InitialSQL |
禁止开机启动
1 |
echo manual | sudo tee /etc/init/mysql.override |
容器化
Dockerfile:
1 2 3 |
FROM mysql:5.5 USER 118 ADD /etc /etc |
创建容器的命令:
1 2 |
docker create --name mysql -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql -v /usr/share/mysql:/usr/share/mysql docker.gmem.cc/mysql |
Leave a Reply