码迷,mamicode.com
首页 > 数据库 > 详细

CentOS7位安装MySql教程

时间:2019-09-23 15:02:55      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:stop   ror   用户名   and   note   restart   container   span   art   

1.先检查系统是否装有mysql

rpm -qa | grep mysql

2.下载mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

 

3.安装 mysql-community-release-el7-5.noarch.rpm包

 

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

 

4.安装MySQL

 

sudo yum install mysql-server

 

5.重置MySQL密码

 

mysql -u root

 

如果报错:

 

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)

 

原因:原因是/var/lib/mysql的访问权限问题。

 

chown root /var/lib/mysql/

 

重启MySQL服务

 

service mysqld restart

 

接着登陆设置密码

 

mysql -u root

 

use mysql;

 

update user set password=password(‘123456‘) where user=‘root‘;

 

exit;

 

6.重启MySQL服务

 

service mysqld restart

 

接着设置Root账户远程连接密码,账户和密码都是 root

 

 mysql -u root -p

 

GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; 

 

重启服务器 

 

service mysqld restart

 

7.使用外网工具连接MySQL

 

连接mysql的用户名和密码都是 root

 

关闭防火墙

 

systemctl stop firewalld.service

 

 

 

 

下面为另一种办法,但是,测试没有成功

连接MySQL服务器,修改密码

 

1)查看初始密码

 

  1. [root@host50 ~]#grep –i ‘password‘ /var/log/mysqld.log
  2. 2017-04-01T18:10:42.948679Z 1 [Note] A temporary password is generated for root@localhost: mtoa>Av<p6Yk //随机生成的管理密码为mtoa>Av<p6Yk

 

2)使用初始密码连接mysql服务

 

  1. [root@host50 ~]# mysql -u root -p‘mtoa>Av<p6Yk‘ //初始密码登录,
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 11
  5. Server version: 5.7.17
  6. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type ‘help;‘ or \hfor help. Type \c‘ to clear the current input statement.
  11. mysql>                                     //登录成功后,进入SQL操作环境

 

3)重置数据库管理员roo本机登录密码

 

  1. mysql> show databases;
  2. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement //提示必须修改密码
  3. mysql> alter user root@”localhost” identified by "123qqq…A"; //修改登陆密码
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql> exit //断开连接
  6. [root@host50 ~]#

 

4)修改密码策略

 

  1. [root@host50 ~]# mysql -uroot –p123qqq…A
  2. mysql>
  3. mysql>set global validate_password_policy=0; //只验证长度
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql>set global validate_password_length=6; //修改密码长度,默认值是8个字符
  6. Query OK, 0 rows affected (0.00 sec)
  7. mysql> alter user root@”localhost” identified by "tarena"; //修改登陆密码
  8. Query OK, 0 rows affected (0.00 sec)
  9. mysql>exit

 

5)使用修改后的密码登录

 

  1. [root@host50 ~]# mysql -uroot -ptarena        //登录
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 15
  4. Server version: 5.7.17 MySQL Community Server (GPL)
  5. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. mysql> show databases; //查看数据库
  10. +--------------------+
  11. | Database |
  12. +--------------------+
  13. | information_schema |
  14. | mysql |
  15. | performance_schema |
  16. | sys                |
  17. +--------------------+
  18. 4 rows in set (0.00 sec)
  19. mysql>

 

 

 

CentOS7位安装MySql教程

标签:stop   ror   用户名   and   note   restart   container   span   art   

原文地址:https://www.cnblogs.com/wwtao/p/11572296.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!