MySQL 5.7.1x 比以往版本安装有些不一样,第一次安装5.7,安装过程遇到挺多小问题,现简单总结安装过程如下。
这次安装的是 mysql-5.7.16-linux-glibc2.5-i686.tar.gz,更多下载参考MySQL 安装(二进制安装模式),
安装相关包(依赖包自动安装):
yum -y install gcc glibc libaio libstdc++ libstdc libncurses ld-linux
配置文件:
# vi /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
user=mysql
port = 3306
server_id = 1
socket=/tmp/mysql.sock
basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
#log-bin=/usr/local/mysql/binlog/mysql-bin
log-error =/var/log/mysql/mysqld.log
pid-file =/var/run/mysqld/mysqld.pid
socket =/tmp/mysql.sock
autocommit = 1
character_set_server=utf8
default-storage-engine=INNODB
transaction_isolation = READ-COMMITTED
event_scheduler = 1
lower_case_table_names=1
max_allowed_packet = 16777216
explicit_defaults_for_timestamp = 1
#binlog_format = row
skip-external-locking
[mysqld_safe]
log-error=/var/log/mysql/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 官网安装参考
http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 750 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql# MySQL 5.7.0 to 5.7.4
shell> bin/mysql_install_db --user=mysql # MySQL 5.7.5
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
创建相关信息:
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
mkdir -p /var/{run/mysqld,log/mysql} /usr/local/mysql/{data,binlog}
chmod 700 /var/{run/mysqld,log/mysql} /usr/local/mysql/{data,binlog}
chown -R mysql:mysql /usr/local/mysql/ /var/{run/mysqld,log/mysql}
安装:
shell> bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --explicit_defaults_for_timestamp
[root@centos224 mysql]# bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --explicit_defaults_for_timestamp
2016-11-22T14:14:53.799055Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-11-22T14:14:54.208059Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-11-22T14:14:54.371661Z 0 [Warning] No existing UUID has been found,
so we assume that this is the first time that this server has been started.
Generating a new UUID: 0a41777d-b0be-11e6-b802-000c29b81537.
2016-11-22T14:14:54.405756Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-11-22T14:14:54.417890Z 1 [Note] A temporary password is generated for root@localhost: AbC#c*hiy0bl
[root@centos224 mysql]#
注意:数据库账号 root@localhost 的密码自动随机生成 AbC#c*hiy0bl (如上所示),登录后要求必须先改密码(也可查看日志信息)。
同样注意 bin/mysqld --defaults-file=/etc/my.cnf 这一行的变量顺序, 否则会报错: unknown variable 'defaults-file=/etc/my.cnf'
配置服务:
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig mysqld on
# service mysqld start
# service mysqld restart
# service mysqld stop
添加环境变量:
# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
# source /etc/profile
访问数据库:
# mysql -u root -p
Enter password:AbC#c*hiy0bl
如果访问忘记密码,错误如下:
# mysql
# mysqladmin -u root password "mysql"
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决:
# service mysqld stop
# cd /usr/local/mysql/bin
# mysqld_safe --skip-grant-tables &
--(再打开另一命令行窗口,直接访问数据库并设置密码)
# source /etc/profile
# mysql -u root
mysql>
mysql> select Host,User from mysql.user;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
mysql> flush privileges;
MySQL 8.0 二进制包部署:
》》》MySQL 8.0 二进制包部署:
# rpm -qa | grep mysql
# rpm -qa | grep mariadb
# yum -y remove mariadb-libs-*
#deploy mysql software
groupadd mysql && useradd -m -d /usr/local/mysql -g mysql mysql
tar -zxvf /tmp/mysql-8.0.19-el7-x86_64.tar.gz -C /usr/local/mysql --strip-components 1
chown -R mysql:mysql /usr/local/mysql
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/bashrc
source /etc/bashrc
》》》创建新的MySQL实例:
#Create mysql data dir for a instance
mkdir -p /u1/mysql/{data,etc,tmp,log,log/binlog,log/relaylog}
chown -R mysql:mysql /u1/mysql
su mysql
#Create mysql configuration file
vi /u1/mysql/etc/my.cnf
#Initialize mysql
mysqld --defaults-file=/u1/mysql/etc/my.cnf --initialize
#Start mysql service
mysqld_safe --defaults-file=/u1/mysql/etc/my.cnf --user=mysql &
#Login mysql and change password for root
mypwd=`cat /u1/mysql/log/error.log | grep "temporary password" | awk '{print $NF}'`
mysql -hlocalhost -P3306 -uroot -p"${mypwd}" -S /u1/mysql/tmp/mysql.sock
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'XXXXXXXXXXX'; --new password for root!
select user,host,plugin,password_last_changed from mysql.user;
#Shutdown mysql service
#mysqladmin -hlocalhost -P3306 -uroot -p -S /u1/mysql/tmp/mysql.sock shutdown