CentOs7.3 安装 MysqL 5.7.19 二进制版本
参考官网 - 使用通用二进制文件在Unix / Linux上安装MySQL
采用二进制方式免编译安装MysqL,适合各类MysqL产品系列,不需要复杂的编译设置和编译时间等待,直接解压下载的软件包,初始化即可完成MysqL的安装和启动.
1.准备工作
依赖环境
关闭防火墙
$ systemctl stop firewalld.service
MysqL依赖于libaio 库
$ yum search libaio $ yum install libaio
下载,解压,重命名
通常解压在 /usr/local/MysqL
把MysqL-5.7.19-linux-glibc2.12-x86_64
文件夹,重命名成MysqL
,这样就凑成/usr/local/MysqL
目录了
$ cd /opt/ $ wget https://dev.MysqL.com/get/Downloads/MysqL-5.7/MysqL-5.7.19-linux-glibc2.12-x86_64.tar.gz $ tar -zxvf /opt/MysqL-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ $ mv /usr/local/MysqL-5.7.19-linux-glibc2.12-x86_64/ /usr/local/MysqL
解压目录内容
bin
MysqLd服务器,客户端和实用程序 data
日志文件,数据库 docs
MysqL手册信息格式 man
Unix手册页 include
包含(标题)文件 lib
库 share
其他支持文件,包括错误消息,示例配置文件,用于数据库安装的sql
2.安装MysqL
$ cd /usr/local/MysqL/ $ groupadd MysqL $ useradd MysqL -g MysqL
2. 创建目录并授权
$ mkdir data MysqL-files $ chmod 750 MysqL-files $ chown -R MysqL . $ chgrp -R MysqL .
3. 初始化MysqL
$ bin/MysqLd --initialize --user=MysqL # MysqL 5.7.6 and up
注意密码
4. MysqL 临时密码
[注意]root@localhost生成临时密码:
;b;s;)/rn6A3
,也就是root@localhost:
后的字符串
2017-08-26T03:23:35.368366Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-08-26T03:23:35.748679Z 0 [Warning] InnoDB: New log files created,LSN=45790 2017-08-26T03:23:35.793190Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-08-26T03:23:35.848286Z 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: f210c54b-8a0d-11e7-abbd-000c29129bb0. 2017-08-26T03:23:35.848889Z 0 [Warning] Gtid table is not ready to be used. Table 'MysqL.gtid_executed' cannot be opened. 2017-08-26T03:23:35.849421Z 1 [Note] A temporary password is generated for root@localhost: ;b;s;)/rn6A3
5. 生成RSA私钥,可以跳过此步骤
MysqL_ssl_rsa_setup
需要openssl
支持,用于启用数据量ssl连接,需要进一步配置。
$ bin/MysqL_ssl_rsa_setup
6. 授予读写权限
$ chown -R root . $ chown -R MysqL data MysqL-files
$ cp support-files/MysqL.server /etc/init.d/MysqL.server
3.启动MysqL服务
启动脚本有两个分别是:
/usr/local/MysqL/bin/MysqLd_safe
/usr/local/MysqL/support-files/MysqL.server
(即/etc/init.d/MysqLd
)
MysqLd_safe
监控MysqLd
服务,记录错误日志,并在MysqLd
因故障停止时将其重启
启动方式一
$ bin/MysqLd_safe --user=MysqL &
启动方式二
$ service MysqL.server start
或者
/usr/local/MysqL/support-files/MysqL.server start
如若出现报错
Starting MysqL.2017-08-26T07:31:24.312411Z MysqLd_safe error: log-error set to '/var/log/mariadb/mariadb.log',however file don't exists. Create writable for user 'MysqL'. ERROR! The server quit without updating PID file (/var/lib/MysqL/node1.pid).
给日志目录授予读写权限
$ mkdir /var/log/mariadb $ touch /var/log/mariadb/mariadb.log $ chown -R MysqL:MysqL /var/log/mariadb
4.登录MysqL
$ /usr/local/MysqL/bin/MysqL -uroot -p Enter password:
如果不知道密码
密码在,安装MysqL步骤 4 ,有提到,怎么找初始化临时密码
如若出现报错
Enter password: ERROR 2002 (HY000): Can't connect to local MysqL server through socket '/tmp/MysqL.sock' (2)
故障分析
查看MysqL实例的状态
$ netstat -ntlp | grep 3306 tcp6 0 0 :::3306 :::* LISTEN 10794/MysqLd
查看my.cnf关于socket的配置
$ more /etc/my.cnf |grep sock socket=/var/lib/MysqL/MysqL.sock
$ vi /etc/my.cnf
修改 [MysqLd]
组下的 socket
路径,我是选择注释掉,加一行为tmp/MysqL.soc
[MysqLd] datadir=/var/lib/MysqL #socket=/var/lib/MysqL/MysqL.sock socket=/tmp/MysqL.sock
重启MysqL 服务
$ service MysqL.server start Shutting down MysqL.. SUCCESS!
再次登录
$ /usr/local/MysqL/bin/MysqL -uroot -p
如果不知道密码
密码在,安装MysqL步骤 4 ,有提到,怎么找初始化临时密码
设置MysqL密码
登陆成功后,设置MysqL密码
MysqL> ALTER USER 'root'@'localhost' identified by 'mima';
或者
MysqL> set password=password("mima");
刷新权限
MysqL> flush privileges; MysqL> exit;
查看MysqL.user表中存在哪些帐户 以及它们的密码是否为空:
MysqL 5.7.6起,使用这个语句:
MysqL> SELECT User,Host,HEX(authentication_string) FROM MysqL.user; +---------------+-----------+------------------------------------------------------------------------------------+ | User | Host | HEX(authentication_string) | +---------------+-----------+------------------------------------------------------------------------------------+ | root | localhost | 2A39383730334637413534333934344644333831383037373636394637344436303631364442324338 | | MysqL.session | localhost | 2A5448495349534E4F544156414C494450415353574F52445448415443414E42455553454448455245 | | MysqL.sys | localhost | 2A5448495349534E4F544156414C494450415353574F52445448415443414E42455553454448455245 | +---------------+-----------+------------------------------------------------------------------------------------+
开启远程登录
关闭防火墙
$ systemctl stop firewalld.service
$ /usr/local/MysqL/bin/MysqL -uroot -p
MysqL> use MysqL; MysqL> update user set host = '%' where user ='root'; MysqL> flush privileges;
第1行:选择MysqL库
第2行:修改host值(以通配符%的内容增加主机/IP地址),当然也可以直接增加IP地址
第3行:刷新MysqL的系统权限相关表
或者
MysqL> grant all privileges on *.* to 'root'@'%' identified by 'mima' with grant option; MysqL> flush privileges;
作者:Peng Lei
版权归作者所有,转载请注明出处