安装Mysql
-
切换阿里云镜像服务
[root@cdh1 ~]# yum -y install wget ## 备份CentOS-Base.repo [root@cdh1 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak [root@cdh1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@cdh1 ~]# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo [root@cdh1 ~]# yum clean all [root@cdh1 ~]# yum makecache
-
下载mysql的yum源
[root@cdh1 ~]# wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
-
安装yum repo源
[root@cdh1 ~]# rpm -ivh mysql57-community-release-el7-7.noarch.rpm
-
查看mysql yum repo是否安装成功
[root@cdh1 ~]# ls /etc/yum.repos.d/ CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Sources.repo epel-7.repo CentOS-Base.repo.bak CentOS-fasttrack.repo CentOS-Vault.repo mysql-community.repo CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo mysql-community-source.repo
-
执行安装mysql
[root@cdh1 ~]# yum install mysql-server [root@cdh1 ~]# yum install mysql-devel [root@cdh1 ~]# yum install mysql
-
若安装过程中,出现这个错误
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-devel-5.7.41-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY Public key for mysql-community-devel-5.7.41-1.el7.x86_64.rpm is not installed mysql-community-devel-5.7.41-1.el7.x86_64.rpm | 4.2 MB 00:01:23 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package. Check that the correct key URLs are configured for this repository. Failing package is: mysql-community-common-5.7.41-1.el7.x86_64 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
需要把MySQL的GPG更新到最新后,再执行上述安装命令
[root@cdh1 ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
-
-
设置开机自动启动mysql
[root@cdh1 ~]# systemctl enable mysqld.service
-
启动mysql
[root@cdh1 ~]# systemctl start mysqld.service
-
开启用户远程链接权限
刚安装,不知道密码,先取消权限认证(生产不要这么玩)
在/etc/my.cnf文件中最后添加一行: skip-grant-tables
重启Mysql
[root@cdh1 ~]# systemctl restart mysqld
进入Mysql,执行以下操作
[root@cdh1 ~]# mysql -uroot -p ## 回车即可 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.41 MySQL Community Server (GPL) Copyright (c) 2000, 2023, Oracle and/or its affiliates. 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> 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> delete from user; Query OK, 3 rows affected (0.00 sec) ## 配置root用户使用密码123456从任何主机都可以连接到mysql服务器 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Query OK, 0 rows affected, 1 warning (0.00 sec) ## 刷新权限 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql>