本来是在学习PostgreSQL,想安装个mySQL 5.7 做一些实践比较,但发现 mysql5.7在centos 7.2上,使用 YUM 怎么也安装不上。刚开始是和MariaDB冲突(centos7.2默认自带mariaDB),使用
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
强制卸载后,紧接又提示:
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit) 2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
无奈之下,才写了这一篇安装mysql5.7的笔记。
下载地址:https://dev.mysql.com/downloads/mysql/
官方文档:https://dev.mysql.com/doc/refman/5.7/en/,或者:http://imysql.com/mysql-refman/5.7/index.html
百度网盘:https://pan.baidu.com/s/1nvacBRr
一、下载、解压
解压后的主要目录、文件如下;
# ll /usr/local/mysql/ drwxr-xr-x bin #mysqld的服务端、客户端以及一些使用程序 drwxr-x--- data #日志文件、数据库文件 drwxr-xr-x include # 头文件 drwxr-xr-x lib #库
二、初始化
2.1 创建用户和组
# groupadd mysql # useradd -r -g mysql -s /bin/false mysql #创建系统用户,且无法登录
2.2 更改文件属主
# mkdir mysql-files # chown -R mysql:mysql /usr/local/mysql/
2.3 创建my.cnf
# touch /etc/my.cnf && chown -R mysql /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data log-error=/var/log/mysql/error.log pid-file=/var/run/mysql/mysql.pid # mkdir -p /var/log/mysql/ && chown -R mysql:mysql /var/log/mysql/ # mkdir -p /var/run/mysql/ && chown -R mysql:mysql /var/run/mysql/
2.4 初始化
# mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql #MySQL 5.7.6 及以上的版本 # mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data #在data的目录下创建ssl的相关文件
-rw-------. 1 root root 1679 10月 13 09:10 private_key.pem -rw-r--r--. 1 root root 451 10月 13 09:10 public_key.pem -rw-r--r--. 1 root root 1078 10月 13 09:10 server-cert.pem -rw-------. 1 root root 1679 10月 13 09:10 server-key.pem
#随机密码
# cat /var/log/mysql/error.log
2017-10-13T09:44:49.713257Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-13T09:44:49.878829Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-10-13T09:44:49.908355Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-10-13T09:44:49.967098Z 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: 27ee4f65-affb-11e7-9e51-0800272bd935.
2017-10-13T09:44:49.968158Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-10-13T09:44:49.969163Z 1 [Note] A temporary password is generated for root@localhost: qtfX,PF%-3o7
2.5 初始化完成后,重置回属主
# chown -R root /usr/local/mysql/ # chown -R mysql data mysql-files
drwxr-xr-x. 2 root mysql 4096 9月 27 00:57 bin -rw-r--r--. 1 root mysql 17987 6月 22 14:13 COPYING drwxr-x---. 5 mysql mysql 4096 10月 13 09:25 data drwxr-xr-x. 2 root mysql 52 9月 27 00:57 docs drwxr-xr-x. 3 root mysql 4096 9月 27 00:57 include drwxr-xr-x. 5 root mysql 4096 9月 27 00:57 lib drwxr-xr-x. 4 root mysql 28 9月 27 00:57 man drwxr-xr-x. 2 mysql mysql 6 10月 13 09:24 mysql-files -rw-r--r--. 1 root mysql 2478 6月 22 14:13 README drwxr-xr-x. 28 root mysql 4096 10月 13 08:48 share drwxr-xr-x. 2 root mysql 86 9月 27 00:57 support-files
2.6 启动
方式一: # mysqld_safe --user=mysql & 方式二:(推荐) # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld # service mysqld start
2.7 修改root密码
# mysql -u root -p #输入前面安装给的随机密码 mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456'); mysql> flush privileges;
2.8 远程链接
mysql> UPDATE mysql.user SET host = '%' WHERE user = 'root'; mysql> flush privileges;
注意和Mysql比较:
Pingback引用通告: Mysql5.7初次安装的注意事项 | 精彩每一天
Pingback引用通告: MariaDB的安装与配置 | 精彩每一天