1. 下载mysql
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
2. 解压mysql
tar -zxvf mysql mysql-5.7.23-linux-glibc2.12-i686.tar.gz
3. 将mysql安装文件移动到系统目录文件夹
cp -r mysql/* /usr/local/mysql
4. 安装mysql
`bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –lc_messages_dir=/usr/local/mysql/share –lc_messages=en_US``
- 遇到问题
bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
- 解决方案
yum -y install numactl
- 遇到问题
[ERROR] Could not open file '/var/log/mysqld.log' for error logging: Permission denied
- 解决方案
touch /var/log/mysqld.log
chown mysql:mysql /var/log/mysqld.log
- 设置mysql快捷启动
ln -s /usr/local/mysql/bin/mysql /usr/bin
- 启动mysql
service start mysql
- 遇到问题
/usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
- 解决方案
chown -R mysql /var/run/mysqld
chgrp -R mysql /var/run/mysqld
service start mysql
- 关闭mysql
systemctl stop mysql
- 遇到问题
Failed to restart mysql.service: Unit not found.
- 解决方案
systemctl enable mysql.service
进入/var/log/mysqld.log 最后一行为密码
- 进入mysql
mysql -uroot -p
- 修改初始密码
set password=password("new password");
- 设置外部访问
use mysql;
update user set host='%' where user='root' and host='localhost';
flush privileges;
- 记录File和Position对应的信息(主库)
show master status;
- 配置同步(从库)
stop slave;
change master to master_host='35.203.167.155:31521', master_user='root',master_password='qwe13579QWE',master_file_log='log.000007',master_log_pos='1357';
- 遇到问题
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'master_file_log=log.000007,master_log_pos=1357' at line 1
- 解决方案(MASTER_LOG_FILE,MASTER_LOG_POS为主库的信息)
CHANGE MASTER TO MASTER_HOST='192.168,1.1', MASTER_PORT=3306,MASTER_USER='root', MASTER_PASSWORD='mypassword', MASTER_LOG_FILE='log.000004', MASTER_LOG_POS=1665;
- 启动同步
start slave;
查看同步状态
show slave status \G;