前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Centos7.4 安装mysql5.7

Centos7.4 安装mysql5.7

作者头像
用户1432189
发布2019-02-25 15:01:58
6400
发布2019-02-25 15:01:58
举报
文章被收录于专栏:zingpLiuzingpLiu

1 安装yum源

代码语言:javascript
复制
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum repolist enabled | grep "mysql.-community."

2 安装mysql

代码语言:javascript
复制
yum -y install mysql-community-server

安装成功后显示:

3 启动和设置开机自启

代码语言:javascript
复制
# 启动和查看启动状态
systemctl start mysqld
systemctl status mysqld

# 开机启动
systemctl enable mysqld
systemctl daemon-reload

4 查看默认root密码

此次安装的是5.7版本,该版本安装成功后,在日志文件/var/log/mysqld.log文件中给root生成了一个默认密码;查看密码:

代码语言:javascript
复制
[@tc_57_161 ~]# grep 'temporary password' /var/log/mysqld.log
2018-03-09T06:15:28.460320Z 1 [Note] A temporary password is generated for root@localhost: ,gjargl63bTr 

可以看到,此次默认root密码是:,gjargl63bTr

5 设置字符编码

代码语言:javascript
复制
vim /etc/my.cnf
# 修改字符编码为utf8
character_set_server = utf8  
init_connect = 'SET NAMES utf8'  

重启生效:systemctl restart mysqld

6 登录报错

代码语言:javascript
复制
[@tc_57_161 etc]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[@tc_57_161 etc]# mysql -u root mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)  

解决办法:

在配置文件/etc/my.cnf最后添加一句:skip-grant-tables;

代码语言:javascript
复制
# mysql -u root mysql 
# update mysql.user set authentication_string=password('admin123') where user='root' and Host = 'localhost';
# flush privileges;
# quit;  

用新密码登录试试:

代码语言:javascript
复制
[@tc_57_161 etc]# mysql -u root -padmin123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.22 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>

成功了!

7 更改root密码

代码语言:javascript
复制
# 改root密码
mysqladmin -uroot -p"旧密码" password "新密码"
mysqladmin -uroot -padmin123 password "123456"
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-06-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 安装yum源
  • 2 安装mysql
  • 3 启动和设置开机自启
  • 4 查看默认root密码
  • 5 设置字符编码
  • 6 登录报错
  • 7 更改root密码
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档