Centos7安装MySql8
title: Centos7安装MySql8
categories:
- mysql
- centos7-mysql8
tags: ‘centos7-mysql8’
想看图片请去原网址搜索,之前写hexo博客没有添加图片库,都是本地,见谅!
前期准备
1、先检查有没有装过mysql
rpm -qa | grep -i mysql
2、如果安装了则需要删除mysql
yum -y remove *-MySQL-*
一般用rpm -e 的命令删除mysql,这样表面上删除了mysql,可是mysql的一些残余程序仍然存在,并且通过第一步的方式也查找不到残余,而yum命令比较强大,可以完全删除mysql.(ps:用rpm删除后再次安装的时候会提示已经安装了,这就是rpm没删除干净的原因)
3、找到并删除mysql的目录
find / -name mysql
查找mysql的一些目录,把所有出现的目录删除,可以使用rm -rf 路径,删除时请注意,一旦删除无法恢复。
4、删除配置文件
rm -rf /etc/my.cnf
5、删除mysql的默认密码
rm -rf /root/.mysql_sercret
删除mysql的默认密码,如果不删除,以后安装mysql这个sercret中的默认密码不会变,使用其中的默认密码就可能会报类似Access denied for user ‘[email protected]’ (using password:yes)的错误.
准备安装
1、配置Mysql 8.0安装源
rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2、安装mysql8.0
yum --enablerepo=mysql80-community install mysql-community-server
看到complet(完毕)就是安装完啦
如果是用安装包安装,service文件要安装在root用户
3、启动mysql服务
[[email protected] opt]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
4、查看mysql服务运行状态
[[email protected] opt]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2019-12-22 14:04:32 CST; 1min 23s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4356 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4444 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─4444 /usr/sbin/mysqld
12月 22 14:04:22 master systemd[1]: Starting MySQL Server...
12月 22 14:04:32 master systemd[1]: Started MySQL Server.
4、查看root临时密码
[[email protected] opt]# grep "A temporary password" /var/log/mysqld.log
2019-12-22T06:04:26.807797Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: /!ECy_whH4D-
5、更改临时密码
输入:mysql -u root -p
在Enter password:后面输入临时密码
登录成功
输入: ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
会提示:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements(密码不符合当前策略)
方案1: 设置符合策略的密码(大小写字母+数据+符号)
方案2:密码策略改简单一点
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘
******
’ at line 1
这个提示是单引号的问题
6、解决密码问题除了设置更复杂的密码还可以更改密码策略
6.1、查看 mysql 初始的密码策略
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.02 sec)
6.2、首先需要设置密码的验证强度等级,设置 validate_password.policy 的全局参数为 LOW 即可,
mysql> set global validate_password.policy=LOW;
Query OK, 0 rows affected (0.00 sec)
6.3、当前密码长度为 8 ,按照通用的来讲,设置为 6 位的密码,设置validate_password.length 的全局参数为 6 即可,
mysql> set global validate_password.length=6;
Query OK, 0 rows affected (0.00 sec)
6.4、现在可以为 mysql 设置简单密码了,只要满足六位的长度即可,
mysql> ALTER USER 'root'@'%' IDENTIFIED BY '******';
Query OK, 0 rows affected (0.01 sec)
6.5、注:在默认密码的长度最小值为 4 ,由 大/小写字母各一个 + 阿拉伯数字一个 + 特殊字符一个,只要设置密码的长度小于 3 ,都将自动设值为 4
6.7、关于 mysql 密码策略相关参数;
-
1)、validate_password.length 固定密码的总长度;
-
2)、validate_password.dictionary_file 指定密码验证的文件路径;
-
3)、validate_password.mixed_case_count 整个密码中至少要包含大/小写字母的总个数;
-
4)、validate_password.number_count 整个密码中至少要包含阿拉伯数字的个数;
-
5)、validate_password.policy 指定密码的强度验证等级,默认为 MEDIUM;
关于 validate_password.policy 的取值:
LOW:只验证长度;
1/MEDIUM:验证长度、数字、大小写、特殊字符;
2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;
validate_password.special_char_count 整个密码中至少要包含特殊字符的个数;
7、退出当前状态
mysql> quit;
Bye
或者这样修改密码,待验证
3.修改密码
mysql>SET PASSWORD=PASSWORD('000000');
8、设置允许远程连接
8.1、连接服务器
[[email protected] opt]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.18 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
8.2、看当前所有数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
8.3、进入mysql数据库
mysql> use mysql;
Database changed
8.4、查看mysql数据库中所有的表
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
33 rows in set (0.00 sec)
8.5、查看user表中的数据
mysql> mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
8.6、修改user表中的Host:
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
% 代表任意的客户端,可替换成具体IP地址。
8.7、刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
9、其他配置
9.1、设置安全选项:(重置)
mysql_secure_installation
9.2、关闭MySQL
systemctl stop mysqld
9.3、重启MySQL
systemctl restart mysqld
9.4、查看MySQL运行状态
systemctl status mysqld
9.5、设置开机启动
systemctl enable mysqld
9.6、关闭开机启动
systemctl disable mysqld
9.7、配置默认编码为utf8:
vi /etc/my.cnf
添加
[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
其他默认配置文件路径:
/etc/my.cnf
日志文件:/var/log/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
9.8、查看版本
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.18 |
+-----------+
1 row in set (0.00 sec)
9.10 命令行导入数据库
mysql -h localhost -u root -p 数据库名< /home/fps001.sql
9.11 命令行导出数据库
mysqldump -h localhost -u root -p 数据库名> /home/fps001.sql
推荐阅读
-
VMware安装ubuntu 20.04操作系统的教程图解
-
linux - php7.0.13 安装完成gd库没有freetype
-
dedecms 顶踩插件 安装后CSS不对。该如何处理
-
安装SQL SERVER2000提示注册表文件被挂起的解决方案
-
linux下eclipse+pdt(PHP集成开发环境安装)
-
如何在Linux上安装Suricata入侵检测系统?
-
CentOS 7下源码安装MySQL 5.6
-
win10环境PHP 7 安装配置【教程】,win10安装配置
-
同时安装vs2005团队开发版和sql 2005企业版的方法(downmoon原作)
-
Windows下安装PHP单元测试环境PHPUnit图文教程_php技巧