linux上安装MySQL
环境:centos7 mysql8.0.18
一、下载mysql服务软件包
地址:
rpm package:是某个特定的包,比如server,client,devle等
rpm bundle:是该版本所有包的集合
compressed tar archive,是源码,必须用源码方式安装
compatibility libraries:兼容库
shared libraries:共享库
development libraries:开发库
test suite:测试套件
client utilities:客户端工具
下载时注意选则好对应的版本
二、安装
(1)rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64
报错信息:
error: failed dependencies:
mariadb-libs is obsoleted by mysql-community-libs-8.0.18-1.el7.x86_64
原因:mariadb-libs和 mysql-community-libs冲突
解决办法:卸载mariadb-libs
a.查询mariadb-libs的包名
[root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
b.卸载该包
[root@izm5e8nyz28va3a786y465z src]# rpm -ev mariadb-libs-5.5.64-1.el7.x86_64
error: failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
报错原因:postfix是mariadb 的依赖包,要先卸载它
[root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep postfix
postfix-2.10.1-7.el7.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -ev postfix-2.10.1-7.el7.x86_64
error: failed dependencies:
/usr/sbin/sendmail is needed by (installed) redhat-lsb-core-4.1-27.el7.centos.1.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -qa |grep redhat-lsb
redhat-lsb-core-4.1-27.el7.centos.1.x86_64
redhat-lsb-submod-security-4.1-27.el7.centos.1.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -ev redhat-lsb-core-4.1-27.el7.centos.1.x86_64
preparing packages...
redhat-lsb-core-4.1-27.el7.centos.1.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -ev postfix-2.10.1-7.el7.x86_64
preparing packages...
postfix-2:2.10.1-7.el7.x86_64
上述步骤成功卸载掉mariadb-libs的依赖
[root@izm5e8nyz28va3a786y465z src]# rpm -ev mariadb-libs-5.5.64-1.el7.x86_64
preparing packages...
mariadb-libs-1:5.5.64-1.el7.x86_64
继续安装:
[root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.18-1.el7.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey
preparing... ################################# [100%]
updating / installing...
1:mysql-community-libs-8.0.18-1.el7################################# [100%]
mysql-community-libs-8.0.18-1.el7包安装成功
(2) rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm
(3) rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm
(4) rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm
error: failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64
libaio.so.1(libaio_0.1)(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64
libaio.so.1(libaio_0.4)(64bit) is needed by mysql-community-server-8.0.18-1.el7.x86_64
解决依赖关系:
[root@izm5e8nyz28va3a786y465z src]# yum list |grep libaio
libaio.i686 0.3.109-13.el7 base
libaio.x86_64 0.3.109-13.el7 base
libaio-devel.i686 0.3.109-13.el7 base
libaio-devel.x86_64 0.3.109-13.el7 base
查询到4个相关的依赖包,只需安装libaio.x86_64 libaio-devel.x86_64
yum -y install libaio.x86_64 libaio-devel.x86_64
[root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.18-1.el7.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey
preparing... ################################# [100%]
updating / installing...
1:mysql-community-server-8.0.18-1.e################################# [100%]
(5)rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm
error: failed dependencies:
pkgconfig(openssl) is needed by mysql-community-devel-8.0.18-1.el7.x86_64
解决依赖关系:
yum -y install openssl openssl-devel
[root@izm5e8nyz28va3a786y465z src]# rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-devel-8.0.18-1.el7.x86_64.rpm: header v3 dsa/sha1 signature, key id 5072e1f5: nokey
preparing... ################################# [100%]
updating / installing...
1:mysql-community-devel-8.0.18-1.el################################# [100%]
至此mysql安装成功
小结:1. 卸载掉冲突组件 mariadb
rpm -ev redhat-lsb-core-4.1-27.el7.centos.1.x86_64 postfix-2.10.1-7.el7.x86_64 mariadb-libs-5.5.64-1.el7.x86_64
2.安装相关依赖:
yum -y install openssl openssl-devel libaio libaio-devel
三、mysql服务设置
1.启动mysql服务:systemctl start mysqld.service
查看mysql服务是否启动:netstat -tunpl |grep mysqld
2.登录mysql修改密码
(1)登录mysql
2种方法:跳过密码验证登录 或 查看初始密码登录
a.查看初始密码登录
cat /var/log/mysqld.log
... 2019-11-11t14:28:57.523108z 5 [note] [my-010454] [server] a temporary password is generated for root@localhost: ,2sg6>hrqdf!
标红加粗部分为初始密码 mysql -uroot -p 键入密码可以登录mysql
b.跳过密码验证登录
修改my.cnf文件,在[mysqld]区域下加入skip-grant-tables 重启mysql
[root@izm5e8nyz28va3a786y465z ~]# find / -name my.cnf
/etc/my.cnf
[root@izm5e8nyz28va3a786y465z ~]# vim /etc/my.cnf
[root@izm5e8nyz28va3a786y465z run]# systemctl restart mysqld.service
[root@izm5e8nyz28va3a786y465z run]# mysql #可直接登录mysql
注意:修改密码后,将my.cnf文件内容还原
(2)修改密码,2sg6>hrqdf!sf
mysql> alter user 'root'@'localhost' identified by 'root123';
error 1819 (hy000): your password does not satisfy the current policy requirements
原因:密码设置的太过简单,初始密码方针:必须包含数字、大写字母、小写字母、特殊符号、长度8位以上。
mysql> flush privileges;
3.设置字符编码(从mysql8.0开始,默认字符集就是utf8mb4 了)
[client]
default-character-set = utf8mb4 #客户端字符编码
[mysqld]
character-set-server = utf8mb4 #服务端字符编码
查看默认字符集:
show global variables like '%character_set%';
查看支持的字符集:
show character set;
4.设置远程登录用户和密码
1.设置已有用户远程登录
update user set host='%' where user='root';
flush privileges;
2.新建远程登录用户
mysql> create user 'xiaobai' identified by 'abc1234!';
mysql> grant all privileges on *.* to 'xiaobai'@'%' with grant option;
mysql>flush privileges;
连接失败,提示 验证插件'caching_sha2_password'不能loade
原因:新版本的mysql使用的是caching_sha2_password验证方式,但此时的navicat还没有支持这种验证方式
解决办法:更改加密方式
查看用户加密方式:
mysql> select user,plugin from user where user='root';
+------+-----------------------+
| user | plugin |
+------+-----------------------+
| root | caching_sha2_password |
+------+-----------------------+
更改加密方式:
mysql> alter user 'root'@'%' identified by ',2sg6>hrqdf!sf' password expire never; #设置密码永不过期
mysql> alter user 'root'@'%' identified with mysql_native_password by ',2sg6>hrqdf!sf'; #设置为老的加密方式
mysql> select user,plugin from user where user='root'; #加密方式已修改成功
+------+-----------------------+
| user | plugin |
+------+-----------------------+
| root | mysql_native_password |
+------+-----------------------+
刷新权限:flush privileges #可连接成功
推荐阅读
-
在Red Hat Enterprise Linux 7.0 x86_64下安装Oracle 11g R2
-
Apache+PHP+MySql 的安装及配置
-
Linux上不区分MySQL表名大小写
-
mysql - 感觉学PHP开发网站到瓶颈了,技术上不知如何突破,希望大神指点推荐几本书,谢谢!
-
php 页面跳转 本土windows 环境正常,上传linux 服务器上跳转不了
-
linux 环境下安装mysql5.6,linuxmysql5.6
-
关于MySQL5.7.18的下载以及安装过程的图文详解
-
与安装MySQL软件的获得
-
RedHat6安装Oracle数据库遇到错误 C [ld-linux-x86-64.so.2+0x14d70]
-
Linux上Oracle误删除一个没有用的dbf表空间文件