当前位置:   article > 正文

centos8.4安装mysql8_centos 安装mysql8.4

centos 安装mysql8.4

1.查看本机是否安装mysql
rpm -qa | grep mysql
如果安装了,如下命令卸载:
yum remove -y XXX包
rm -rf /var/lib/mysql && rm -rf /etc/my.cnf && rm -rf /usr/share/mysql
find / -name mysql

2.安装rpm包
yum localinstall rpm包

3.安装服务
yum install mysql-server

rpm -qa | grep -i mysql

编辑 vim /etc/my.cnf.d/mysql-server.cnf
在[mysqld]后末行添加 :

lower_case_table_names=1

win下默认值是1,mac是2,linux是0。
0:区分大小写
1:不区分
2:部分区分

查看mysql区分到小写命令:
show Variables like 'lower_case_table_names';

4.查看mysql是否安装成功
ps -ef | grep mysql
mysqladmin --version

5.启动服务
systemctl start mysqld.service

6.mysql登录
mysql  本机命令行无密码登录
use mysql
修改root密码:
alter user 'root'@'localhost' identified by 'root@123456';


mysql -uroot -p123456
如果提示: Access denied for user 'root'@'localhost' (using password: YES)
6.1编辑 vim /etc/my.cnf.d/mysql-server.cnf
在[mysqld]后添加一行
skip-grant-tables

6.2保存后重启mysql服务
systemctl restart mysqld.service

mysql
use mysql
将authentication_string置空
update user set authentication_string='' where User='root';

quit退出mysql命令行,重启mysql
mysql -uroot -p mysql   不输入密码进入mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
flush privileges;

可以设置远程访问:
update user set host = '%' where user ='root';
ALTER USER 'root'@'%' IDENTIFIED BY '123456';
flush privileges;
select User,Host from user;

mysql -uroot -p mysql  命令行输入密码可以访问

如果客户端不能访问,请坐如下修改
修改加密方式
ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
更新用户密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
刷新一下权限 
flush privileges;

7.卸载mysql8

查看已经安装的mysql程序:
rpm -qa | grep -i mysql
mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64
mysql-errmsg-8.0.26-1.module_el8.4.0+915+de215114.x86_64
mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64
mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64

卸载msyql程序:
rpm -ev mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64
rpm -ev mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64
rpm -ev mysql-errmsg-8.0.26-1.module_el8.4.0+915+de215114.x86_64
rpm -ev mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64

查看对应的mysql目录:
find / -name msyql
/var/log/mysql
/var/lib/selinux/targeted/active/modules/100/mysql
/usr/share/bash-completion/completions/mysql
/usr/share/selinux/packages/mysql
/usr/share/selinux/targeted/default/active/modules/100/mysql

删除对应目录文件,不删除和docker有关的:
rm -rf /var/log/mysql
rm -rf /var/lib/selinux/targeted/active/modules/100/mysql
rm -rf /usr/share/bash-completion/completions/mysql
rm -rf /usr/share/selinux/packages/mysql
rm -rf /usr/share/selinux/targeted/default/active/modules/100/mysql

删除配置文件
rm -rf /etc/my.cnf

8.mysql8导入如数据脚本报错
导入数据库提示错误[Err] 1067 - Invalid default value for 'date_added'
查看sql_mode:
 select @@global.sql_mode;
+-----------------------------------------------------------------------------------------------------------------------+
| @@global.sql_mode                                                                                                     |
+-----------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

设置sql_mode
set @@global.sql_mode='NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES';

navicat或者其他工具导入数据

导入数据成功后还原:
 set @@global.sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/682908
推荐阅读
相关标签
  

闽ICP备14008679号