1、拉取稳定的mysql5.7.25版本
docker pull mysql:5.7.25
2、创建并运行容器
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.25
Linux安装mysql
1、检查mysql用户组和用户是否存在,如果没有,则创建
[root@localhost /]# cat /etc/group | grepmysql
[root@localhost/]# cat /etc/passwd |grepmysql
[root@localhost/]# groupadd mysql
[root@localhost/]# useradd -r -g mysql mysql
[root@localhost/]#
2、下载mysql的linux版本
[root@localhost /]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
3、解压》移到usr/local目录》重命名
[root@localhost /]# tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost/]# lsmysql-5.7.24-linux-glibc2.12-x86_64
mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@localhost/]# mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/[root@localhost/]# cd /usr/local/
#重命令文件夹
[root@localhost/]# mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
4、创建data文件夹》给mysql文件夹授权》进行编译
[root@localhost /]# mkdir /usr/local/mysql/data
[root@localhost/]# chown -R mysql:mysql /usr/local/mysql
[root@localhost/]# chmod -R 755 /usr/local/mysql
[root@localhost/]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
这步如果报错:有libaio字样,则安装libaio
[root@localhost bin]# rpm -qa|greplibaio
[root@localhost bin]#
[root@localhost bin]#yum install libaio-devel.x86_64
如果报错:有libnumal.o.i,则安装numactl
[root@localhost bin]# yum -y install numactl
5、编译通过后,关注打印的日志,root@localhost:密码,记住初始密码
[Note] A temporary password is generated for root@localhost: ktM#x,SYH7Ug
6、修改my.cnf配置文件
[root@localhost bin]# vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
port= 3306sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0max_connections=400innodb_file_per_table=1#表名大小写不明感,敏感为
lower_case_table_names=1
7、启动mysql服务
[root@localhost /]# /usr/local/mysql/support-files/mysql.server start
启动服务如果报错,则看是否存在mysql和mysqld的服务,如果存在,则结束进程,再重新执行启动命令
#报错信息
Starting MySQL... ERROR! The server quit without updating PID file#查询服务ps -ef|grepmysqlps -ef|grepmysqld
#结束进程kill -9PID
#启动服务/usr/local/mysql/support-files/mysql.server start
8、建立软连接,重启mysql
[root@localhost /]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost/]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@localhost/]# service mysql restart
9、进入mysql修改初始密码
[root@localhost /]# mysql -u root -p
Enter password:
mysql>set password for root@localhost = password('root');
mysql>update user set host = '%' where user = 'root';
mysql> selecthost,user from user;+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
3 rows in set (0.00 sec)
10、设置开机启动
#将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost/]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#赋予可执行权限
[root@localhost/]# chmod +x /etc/init.d/mysqld
#添加服务
[root@localhost/]# chkconfig --add mysqld
#显示服务列表
[root@localhost/]# chkconfig --list
11、创建可远程连接用户
drop user 'canal'@'%';
CREATE USER'canal'@'%' IDENTIFIED BY 'canal';
grant all privileges on*.* to 'canal'@'%' identified by 'canal';
flush privileges;