CentOS7 yum 安装 MySQL 原创 数据库 2022年3月10日 11:56 夏至未至 982 当前内容 4107 字,在路上,马上到,马上到 #### 下载mysql官方的yum源 [root@localhost /]# wget -i http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm #### 安装源 [root@localhost /]# yum -y install mysql57-community-release-el7-10.noarch.rpm 这一步如果报错:Another app is currently holding the yum lock; waiting for it to exit... [参考这里处理](https://www.codecomeon.com/posts/126/ "参考这里处理")。 #### 安装mysql [root@localhost /]# yum -y install mysql-community-server 这一步如果有如下报错: ... Failing package is: mysql-community-libs-compat-5.7.37-1.el7.x86_64 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql ... 通过编辑 `/etc/yum.repos.d/mysql-community.repo`,修改以下内容解决: [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 其实通过这个yum源,就能看出来,mysql56、57、80都是可以安装的,跟此参数 enabled=1 有关,感兴趣可以测试。 即:gpgcheck=0 #### 启动默认实例 systemctl start mysqld 查看实例状态: [root@localhost /]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2022-03-09 19:50:54 PST; 3s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 4699 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 4646 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 4702 (mysqld) Tasks: 27 CGroup: /system.slice/mysqld.service └─4702 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Mar 09 19:50:47 localhost.localdomain systemd[1]: Starting MySQL Server... Mar 09 19:50:54 localhost.localdomain systemd[1]: Started MySQL Server. [root@localhost /]# #### 修改实例密码 先从日志查看默认密码,通过默认密码登陆后,修改默认密码: [root@localhost /]# grep "password" /var/log/mysqld.log 2022-03-10T03:50:51.843207Z 1 [Note] A temporary password is generated for root@localhost: .lhpu:dKO1s, [root@localhost /]# 连接数据库: [root@localhost /]# mysql -uroot -p'.lhpu:dKO1s,' 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.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, 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> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length=1; Query OK, 0 rows affected (0.00 sec) 修改密码: mysql> mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) #### 设置实例远程连接 mysql> mysql> grant all on *.* to root@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> #### 验证实例 [root@localhost /]# mysql -uroot -p123456 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 3 Server version: 5.7.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, 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> #### 删除yum源 防止自更新,需要移除安装的yum源 [root@localhost /]# yum -y remove mysql57-community-release-el7-10.noarch 最后,如果此虚拟机无法连接外网,那我们还有[其他安装方式](https://www.codecomeon.com/posts/46/ "其他安装方式"),欢迎尝试。 本文标题: CentOS7 yum 安装 MySQL 本文作者: 夏至未至 发布时间: 2022年3月10日 11:56 最近更新: 2022年3月10日 16:55 原文链接: 许可协议: 署名-非商业性-禁止演绎 4.0 国际(CC BY-NC-ND 4.0) 请按协议转载并保留原文链接及作者 MySQL(28) Linux(24) 上一个 Linux系统修改主机名(实操) 下一个 Another app is currently holding the yum lock 已解决 当前文章评论暂未开放,请移步至留言处留言。