文章目录
环境
- centos 7 或 8
- MySQL 5.7.17
centos 版 mysql 下载地址
安装
创建文件夹保存上传文件
mkdir mysqltools
解压tar包
tar -zxvf mysql-5.7.17.tar.gz
监测是否本机已安装
- 检测 mariadb
[root@VM_0_17_centos mysqltools]# rpm -qa |grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
- 删除已安装
[root@VM_0_17_centos mysqltools]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@VM_0_17_centos mysqltools]# rpm -qa |grep mariadb
安装rpm文件
rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.17-1.el7.x86_64.rpm
异常
1、安装失败
出现下列类型问题:
使用命令忽略依赖包
、强制解压安装
,使用--force --nodeps
:
rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm --force --nodeps
2、mysql-community-server 安装失败
如下所示报错:
[root@VM_0_17_centos mysqltools]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.17-1.el7.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.17-1.el7.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.17-1.el7.x86_64
则需要安装依赖文件:
[root@VM_0_17_centos mysqltools]# yum install numactl
获取临时登录密钥
[root@VM_0_17_centos mysqltools]# grep 'temporary password' /var/log/mysqld.log
2018-09-04T08:32:15.877855Z 1 [Note] A temporary password is generated for root@localhost: B4fe(f&R,j!F
其中 B4fe(f&R,j!F
就是默认密钥 使用其进行登陆操作
登录mysql
[root@VM_0_17_centos mysqltools]# mysql -u root -p
Enter password:
修改数据库密码
5.7 中密钥强度要求更高 需要特殊字符、大小写、数字等拼接最少8位长度的字符串!
mysql> alter user root@localhost identified by '你的数据库密码';
mysql> flush privileges;
开放访问权限
mysql> grant all privileges on *.* to root@'%'identified by '你所修改的密钥';
操作执行完成后,一定要记得刷新
!
刷新配置
mysql> flush privileges;
退出mysql,重启服务
mysql> quit;
[root@VM_0_17_centos mysqltools]# service mysqld restart
centos 8的问题
如果出现下列报错信息,则表示缺少相关的库文件:
使用下列命令:
yum install libncurses*
表名大小写异常
修改centos系统中mysql的配置文件。
[root@VM-0-13-centos ~]# cd /etc/
在my.cnf
的[mysqld]
中增加下列命令配置。
lower_case_table_names=1
退出!保存!重启mysql服务!
[root@VM-0-13-centos etc]# service mysqld restart
Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY 相关异常
出错原因:
MySQL 5.7.5 及以上功能依赖检测功能,而我使用的mysql是8.0版本。如果启用了ONLY_FULL_GROUP_BY SQL 模式(默认情况下),MySQL将拒绝选择列表,HAVING 条件或 ORDER BY 列表的查询引用在 GROUP BY 子句中既未命名的非集合列,也不在功能上依赖于它们。
在/etc/my.cnf
文件的[mysqld]
中增加下列命令:
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
退出!保存!重启mysql服务!
[root@VM-0-13-centos etc]# service mysqld restart
该异常参考博文:Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY错误