MySql教程

centos7安装mysql

本文主要是介绍centos7安装mysql,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

mysql安装过程

[root@weikeu ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
[root@weikeu ~]# yum localinstall mysql57-community-release-el7-11.noarch.rpm

[root@weikeu ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community                 108
mysql-tools-community/x86_64      MySQL Tools Community                       90
mysql57-community/x86_64          MySQL 5.7 Community Server                 347
[root@weikeu ~]# yum install mysql-community-server –y

[root@weikeu ~]# systemctl start mysqld.service
[root@weikeu ~]# ps -ef | grep mysql
[root@weikeu ~]# systemctl enable mysqld.service

[root@weikeu ~]# grep 'temporary password' /var/log/mysqld.log
2019-06-04T11:59:01.477099Z 1 [Note] A temporary password is generated for root@localhost: P0Deait,dWr6

[root@weikeu ~]# mysql -p'P0Deait,dWr6'
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 2
Server version: 5.7.26
 
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.
 
mysql>
mysql> SET PASSWORD = PASSWORD("AWas@4@5##ji5");
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql> ALTER USER  'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'AWas@4@5##ji5' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

image-20211112160628888

Mysql8安装及问题总结

Mysql8安装成功后,首次进入mysql

cat mysqld.log | grep password

找到临时密码

mysql -uroot -p 输入临时密码登录成功

输入mysql语句报错 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

解决方法 alter user 'root'@'localhost' identified by '你的密码包含大小写及特殊符号8位以上';

flush privileges;

\q退出

使用新密码,重新登录mysql -uroot -p

image-20211112160709964

允许root用户远程访问,则要修改权限

1.登录数据库

mysql -uroot -p 回车

输入密码… 回车

2.登录成功后,切换数据库

use mysql;

3.查看当前用户

select user,host from user;

4.允许root用户远程访问

update user set host='%' where user='root';

GRANT ALL ON . TO 'root'@'%';

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的数据库密码';

image-20211112160738614

image-20211112160805180

image-20211112160826691

Navicat远程连接数据库成功

建站时无法连接数据库,报错The server requested authentication method unknown to the client

这是因为mysql8 验证方式与之前的版本不同

在my.cnf中加一句:
default_authentication_plugin=mysql_native_password
变成原来的验证方式即可

这篇关于centos7安装mysql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!