Centos安装Mysql

2021-07-24  本文已影响0人  小二哥很二

这里介绍的是yum安装,数据库8.0

1、下载yum源:https://dev.mysql.com/downloads/repo/yum/
注意点击对应的系统版本~

yum源 复制链接地址

2、执行:wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
得到 mysql80-community-release-el7-3.noarch.rpm

[root@iZwz9ga2spyeb5u9tdq8t5Z default]# ls
grub  mysql80-community-release-el7-3.noarch.rpm  nss  useradd

3、安装资源包:yum install mysql80-community-release-el7-3.noarch.rpm -y
4、查看资源包仓库

[root@iZwz9ga2spyeb5u9tdq8t5Z default]# yum repolist|grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                 212
mysql-tools-community/x86_64      MySQL Tools Community                      132
mysql80-community/x86_64          MySQL 8.0 Community Server                 283

4、安装:yum install mysql-community-server -y
5、启动:systemctl start mysqld

[root@iZwz9ga2spyeb5u9tdq8t5Z default]# ps -aux|grep mysql
mysql    15511 40.2 19.4 1313080 366352 ?      Ssl  13:43   0:01 /usr/sbin/mysqld
root     15649  0.0  0.0 112824   980 pts/0    R+   13:43   0:00 grep --color=auto mysql
[root@iZwz9ga2spyeb5u9tdq8t5Z default]# mysql --version
mysql  Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)

6、查看数据库登录密码:cat /var/log/mysqld.log |grep password

[root@iZwz9ga2spyeb5u9tdq8t5Z default]# cat /var/log/mysqld.log |grep password
2021-07-24T05:43:37.091643Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: =rsa%f%+T7j<
[root@iZwz9ga2spyeb5u9tdq8t5Z default]# 

7、登录:mysql -uroot -p,并输入上面的密码

[root@iZwz9ga2spyeb5u9tdq8t5Z default]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

8、报错处理
上面一步看到,输入密码后报错,那么解决方案是在my.cnf里面,在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程

9、清空root密码

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string='' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> exit
Bye

10、更改root密码:上一步清空了密码,那么就可以免密登录了

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# skip-grant-tables
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
-- 插入 --  
mysql> alter user user() identified by "xxxxxxx";
Query OK, 0 rows affected (0.00 sec)
#  刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

11、设置允许远程用户访问:GRANT ALL ON *.* TO 'root'@'%'

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> update user set host = '%' where user = 'root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

12、登录Navicat
此时就可以登录远程连接Mysql了~

上一篇 下一篇

猜你喜欢

热点阅读