CentOS7位安装MySql教程
Posted wwtao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7位安装MySql教程相关的知识,希望对你有一定的参考价值。
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)查看初始密码
- [root@host50 ~]#grep –i ‘password‘ /var/log/mysqld.log
- 2017-04-01T18:10:42.948679Z 1 [Note] A temporary password is generated for root@localhost: mtoa>Av<p6Yk //随机生成的管理密码为mtoa>Av<p6Yk
2)使用初始密码连接mysql服务
- [root@host50 ~]# mysql -u root -p‘mtoa>Av<p6Yk‘ //初始密码登录,
- 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.17
- Copyright (c) 2000, 2016, 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> //登录成功后,进入SQL操作环境
3)重置数据库管理员roo本机登录密码
- mysql> show databases;
- ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement //提示必须修改密码
- mysql> alter user root@”localhost” identified by "123qqq…A"; //修改登陆密码
- Query OK, 0 rows affected (0.00 sec)
- mysql> exit //断开连接
- [root@host50 ~]#
4)修改密码策略
- [root@host50 ~]# mysql -uroot –p123qqq…A
- mysql>
- mysql>set global validate_password_policy=0; //只验证长度
- Query OK, 0 rows affected (0.00 sec)
- mysql>set global validate_password_length=6; //修改密码长度,默认值是8个字符
- Query OK, 0 rows affected (0.00 sec)
- mysql> alter user root@”localhost” identified by "tarena"; //修改登陆密码
- Query OK, 0 rows affected (0.00 sec)
- mysql>exit
5)使用修改后的密码登录
- [root@host50 ~]# mysql -uroot -ptarena //登录
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 15
- Server version: 5.7.17 MySQL Community Server (GPL)
- Copyright (c) 2000, 2016, 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.
- mysql> show databases; //查看数据库
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | sys |
- +--------------------+
- 4 rows in set (0.00 sec)
- mysql>
以上是关于CentOS7位安装MySql教程的主要内容,如果未能解决你的问题,请参考以下文章