#设置主机名 本次安装5.7版本 hostnamectl --static set-hostname mysql #查看内核 [root@mysql ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
根据你OS的版本去官网上寻找所需rpm包
https://dev.mysql.com/downloads/repo/yum/
-
yum存储库安装
yum -y install wgetwget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpmyum install mysql80-community-release-el7-7.noarch.rpm -y#yum源查看[root@mysql ~]# ls /etc/yum.repos.d/ | grep mysqlmysql-community-debuginfo.repomysql-community.repomysql-community-source.repo#支持多个版本[root@mysql ~]# yum repolist all | grep mysqlmysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Comm 禁用mysql-cluster-7.5-community-source MySQL Cluster 7.5 Comm 禁用mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Comm 禁用mysql-cluster-7.6-community-source MySQL Cluster 7.6 Comm 禁用mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Comm 禁用mysql-cluster-8.0-community-debuginfo/x86_64 MySQL Cluster 8.0 Comm 禁用mysql-cluster-8.0-community-source MySQL Cluster 8.0 Comm 禁用mysql-connectors-community/x86_64 MySQL Connectors Commu 启用: 220mysql-connectors-community-debuginfo/x86_64 MySQL Connectors Commu 禁用mysql-connectors-community-source MySQL Connectors Commu 禁用mysql-tools-community/x86_64 MySQL Tools Community 启用: 98mysql-tools-community-debuginfo/x86_64 MySQL Tools Community 禁用mysql-tools-community-source MySQL Tools Community 禁用mysql-tools-preview/x86_64 MySQL Tools Preview 禁用mysql-tools-preview-source MySQL Tools Preview - 禁用mysql57-community/x86_64 MySQL 5.7 Community Se 禁用mysql57-community-source MySQL 5.7 Community Se 禁用mysql80-community/x86_64 MySQL 8.0 Community Se 启用: 405mysql80-community-debuginfo/x86_64 MySQL 8.0 Community Se 禁用mysql80-community-source MySQL 8.0 Community Se 禁用 #安装yum工具包yum -y install yum-utils#禁用8.0 开启5.7yum-config-manager --disable mysql80-communityyum-config-manager --enable mysql57-community[root@mysql ~]# yum repolist enabled | grep mysqlmysql-connectors-community/x86_64 MySQL Connectors Community 220mysql-tools-community/x86_64 MySQL Tools Community 98mysql57-community/x86_64 MySQL 5.7 Community Server 660
-
安装mysql
yum -y install mysql-community-server mysql #安装mysql客户端 服务端 #开启mysql 设置开机自启 systemctl start mysqld systemctl enable mysqld #查看安装 ls /var/lib/mysql #查看mysql状态 [root@mysql ~]# systemctl status mysqld● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 一 2023-06-12 11:11:12 EDT; 43s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 50360 (mysqld) CGroup: /system.slice/mysqld.service └─50360 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid6月 12 11:11:07 mysql systemd[1]: Starting MySQL Server...6月 12 11:11:12 mysql systemd[1]: Started MySQL Server.#查看初始密码[root@mysql ~]# grep 'password' /var/log/mysqld.log2023-06-12T15:11:08.867826Z 1 [Note] A temporary password is generated for root@localhost: 8s*e9<_d=SI&#初次登录mysql[root@mysql ~]# mysql -uroot -p'8s*e9<_d=SI&'
-
修改密码,设置权限
mysql> show databases;ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. --必须重新设置密码--设置密码 符合规则 包含大小写数字特殊符号不低于8位mysql> alter user 'root'@'localhost' identified by 'Rkun18.mysql';Query OK, 0 rows affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.01 sec)--创建一个用户 设置密码并授权mysql> grant select,drop,insert on *.* to 'rkun18'@'localhost' identified by 'Rkun18.mysql';Query OK, 0 rows affected, 1 warning (0.01 sec)--查看用户mysql> select user,host from mysql.user;+---------------+-----------+| user | host |+---------------+-----------+| mysql.session | localhost || mysql.sys | localhost || rkun18 | localhost || root | localhost |+---------------+-----------+4 rows in set (0.00 sec)--刷新权限列表mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)--查看用户权限mysql> show grants for 'rkun18'@'localhost';+-----------------------------------------------------------+| Grants for rkun18@localhost |+-----------------------------------------------------------+| GRANT SELECT, INSERT, DROP ON *.* TO 'rkun18'@'localhost' |+-----------------------------------------------------------+1 row in set (0.00 sec)
来源地址:https://blog.csdn.net/weixin_51882166/article/details/131316837