CentOS7.4安装MySQL踩坑记录
CentOS7.4安装MySQL踩坑记录
time: 2018.3.19
CentOS7.4安装MySQL时网上的文档虽然多但是不靠谱的也多, 可能因为版本与时间的问题, 所以记录下自己踩坑的过程, 如果你发现进坑了, 欢迎参考本篇文章:)
- 第一次尝试遇到的问题:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
尝试卸载重新安装, 参考, 步骤:
1.查看yum是否安装过mysql
yum list installed mysql*
yum list installed | grep mysql*
没有显示结果, 说明yum中没有安装mysql(对yum与rpm并不是很了解, 如有错误欢迎指出)
2.删除配置文件与文件夹
rm -rf /var/lib/mysql
rm /etc/my.cnf
3.查看rpm中的安装并卸载
rpm -qa | grep -i mysql
以下根据上面命令显示的列表修改
rpm -e mysql-community-server-5.7.21-1.el7.x86_64 mysql-community-common-5.7.21-1.el7.x86_64 mysql-community-libs-5.7.21-1.el7.x86_64 mysql57-community-release-el7-11.noarch mysql-community-client-5.7.21-1.el7.x86_64 mysql-community-libs-compat-5.7.21-1.el7.x86_64 --nodeps
3.清除余项
whereis mysql
删除上面命令显示的路径
rm -rf /usr/share/mysql/
4.删除配置
rm -rf /usr/my.cnf
rm -rf /root/.mysql*
# 无结果
# 笔者机器上无结果
chkconfig --list | grep -i mysql
chkconfig --del mysqld
systemctl list-dependencies | grep -i mysql
5.重新安装
下载mysql源并安装到rpm:
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
更新yum并安装mysql(时间较长):
# 更新yum软件包
yum check-update
# 更新系统
yum update
# 安装mysql
yum install mysql mysql-server
注意事项
更新yum后可能需要重新编辑/usr/bin/yum
文件头(因为笔者将默认的python更改为python3), 编辑后再次安装即可, 出现的错误如下:
[root@centos ~]# yum install mysql mysql-server
File "/usr/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax
安装完成后配置
未跳过
grant-tables
授权表时启动MySQL会出现:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
这里需要修改root的密码, 这条命令是给mysql加上一个启动参数--skip-grant-tables
, 顾名思义,就是在启动mysql时不启动grant-tables
授权表, 用于忘记管理员密码后的修改
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables --user=mysql &
但是, MySQL 5.7.6
版本开始默认是不安装mysqld_safe
了, 以下为新方法:
1.停止 mysql 服务
service mysqld stop
2.设置 mysqld 选项 --skip-grant-tables
参数:
systemctl set-environment MYSQLD_OPTS='--skip-grant-tables'
3.重新启动mysql
systemctl start mysqld
4.执行 mysql -u root
登录mysql并更改密码
[root@centos ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.
mysql> UPDATE mysql.user
-> SET authentication_string = PASSWORD('toor'), password_expired = 'N'
-> WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.65 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
password_expired = 'N'
过期状态设置为No,flush privileges;
刷新权限记录, 详见
5.设置完密码后去掉--skip-grant-tables
参数, 重启mysql即可用设置的密码登录root用户
systemctl unset-environment MYSQLD_OPTS
systemctl restart mysqld
mysql -uroot -p
MySQL5.7开启远程连接
1.连接到mysql数据库
mysql -uroot -p
2.选择数据库
use mysql
3.开启远程连接:
# mysql安装后默认是localhost访问,如果需要外部访问可以设置一个新的账号把host改为%,意味着所有ip均可以访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
由于密码策略问题报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
原因: MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格。
使用了该插件会检查设置的密码是否符合当前设置的强度规则,若不满足则拒绝设置。影响的语句和函数有:create user,grant,set password,password(),old password。
解决参考:
# 查看mysql全局参数配置
mysql> select @@validate_password_policy;
+----------------------------+
| @@validate_password_policy |
+----------------------------+
| MEDIUM |
+----------------------------+
1 row in set (0.01 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| 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.00 sec)
# 修改mysql参数配置
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_special_char_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 3 |
| validate_password_mixed_case_count | 0 |
| validate_password_number_count | 3 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 0 |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
# 配置完即可修改简单密码
mysql> set password for 'root'@'localhost' = password('简单密码');
Query OK, 0 rows affected, 1 warning (0.00 sec)
4.重新配置并重启服务
# 此时配置远程连接无报错
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '简单密码' WITH GRANT OPTIONN;
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> ^DBye
# 重启mysql服务
systemctl restart mysqld.service
ok, 可以远程连接了
CentOS7.4安装MySQL踩坑记录的更多相关文章
- 虚拟机安装mysql踩坑记录
本章节主要讲解的是在虚拟机centOs7版本以上安装mysql5.6版本,亲测可以直接使用,有需要帮助的小伙伴可以加本人QQ2246451792@qq.com!!!! 卸载centOs7自带的mari ...
- centos7安装Mysql爬坑记录
centos7安装Mysql爬坑记录 查看是否已安装 使用下列命令查看是否已经安装过mysql/mariadb/PostgreSQL 如果未安装,不返回任何结果(ECS的centos镜像默认未安装 ...
- ubuntu 下安装docker 踩坑记录
ubuntu 下安装docker 踩坑记录 # Setp : 移除旧版本Docker sudo apt-get remove docker docker-engine docker.io # Step ...
- Asp.Net Core Identity+EFCore + Mysql踩坑记录
搭建基础框架准备试试传说中的Identity,本以为很顺利,结果一路踩了N多坑 遂就把过程记录下来.方便自己以后查看,也希望能帮到遇到同样问题的朋友. 1.首先,引入Identity需要的类库,还有M ...
- 安装mysql采坑记录
安装之前彻底卸载之前的mysql,再次安装,初始化数据库那一步失败. 再次彻底卸载mysql,把原先的安装路径的文件夹删除,文件夹路径:C:\ProgramData,再次安装,成功. 总结:重装mys ...
- Ubuntu mysql踩坑记录
安装: 1.sudo apt-get install mysql-server 2. apt-get isntall mysql-client 3. sudo apt-get install lib ...
- 在 ASP.NET Core 中使用 MySql 踩坑记录
使用 Pomelo.EntityFrameworkCore.MySql 生成 MySQL 数据库 关于如何使用请查看项目文档即可 组件地址:https://github.com/PomeloFound ...
- Android关于版本更新下载安装之踩坑记录(针对7.0以上)
最近刚刚把古老的项目targetSdk版本升级到26,升级之前是19(非常非常古老了).那么升级后一些问题开始出现. Android 8.0 (Android O)为了针对一些流氓软件引导用户安装其他 ...
- windows 安装 python 踩坑记录
官方不建议使用 64 bit python,容易出各种问题 Unable to find vcvarsall.bat 凡是安装与操作系统底层相关的 python 扩展都会遇到这个问题,如 PIL,Pi ...
随机推荐
- Spring中的@scope注解
默认是单例模式,即scope="singleton".另外scope还有prototype.request.session.global session作用域.scope=&quo ...
- MysqL_SELECT FOR UPDATE详解
先来举一个在某些应用场景下会出现数据不一致的例子,当然存储引擎是InnoDB(至于为什么,后面再告诉你). 电商平台常见的下单场景: 一般商品表(goods)有基本的四个字段,id(主键),goods ...
- LeetCode第四天
leetcode 第四天 2018年1月4日 15.(628)Maximum Product of Three Numbers JAVA class Solution { public int max ...
- HDU - 1213 dfs求联通块or并查集
思路:给定一个无向图,判断有几个联通块. AC代码 #include <cstdio> #include <cmath> #include <algorithm> ...
- nyoj137 取石子(三) 楼教主男人八题之一
思路:一堆时,N态.两堆时,当两堆数量相同,P态,不同为N态.三堆时,先手可以变成两堆一样的,必胜N态. 此时可以总结规律:堆数为偶数可能且石子数都是两两相同的,为P态.分析四堆时,当四堆中两两数量一 ...
- SpringBoot SpringSecurity4整合,灵活权限配置,弃用注解方式.
SpringSecurity 可以使用注解对方法进行细颗粒权限控制,但是很不灵活,必须在编码期间,就已经写死权限 其实关于SpringSecurity,大部分类都不需要重写,需要的只是妥善的配置. 每 ...
- nignx
1. 什么是nginx Nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够 ...
- SPFA+SLF+LLL优化模板
#include<algorithm> #include <iostream> #include <cstdlib> #include <cstring> ...
- php程序员的成长之路
第一阶段:基础阶段(基础PHP程序员) 重点:把LNMP搞熟练(核心是安装配置基本操作) 目标:能够完成基本的LNMP系统安装,简单配置维护:能够做基本的简单系统的php开发:能够在PHP中型系统中支 ...
- R+tmcn笔记︱tmcn包的基本内容以及李舰老师R语言大会展示内容摘录
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- tmcn包目前托管在在R-forge 上开发和 ...