1、下载 mysql5.7 的rpm包 wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
2.安装rpm包 rpm -ivh mysql57-community-release-el7-9.noarch.rpm
执行完成后会在/etc/yum.repos.d/目录下生成两个repo文件:mysql-community.repo、mysql-community-source.repo
ls /etc/yum.repos.d/
二、yum安装 注意:必须进入到 /etc/yum.repos.d/目录后再执行以下脚本 cd /etc/yum.repos.d/ 安装 yum install mysql-server -y
报错:仓库 "MySQL 5.7 Community Server" 的 GPG 密钥已安装,但是不适用于此软件包。请检查仓库的公 钥 URL 是否配置正确 成功处理的方法记录下。 rm /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql? rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022?
1、启动 systemctl enable mysqld // 开机启动 systemctl start mysqld
2.获取临时登录密码(首次登录) grep 'temporary password' /var/log/mysqld.log
3.登录 mysql -u root -p 然后输入密码(刚刚获取的临时密码)
4.重置密码 查看 mysql 初始的密码策略 SHOW VARIABLES LIKE 'validate_password%'; 设置密码:长度大于8位,含大写字母、小写字母、数字、标点符号。如:Mysql:01 set password = password("yourpassword");?
四、远程访问 ## 使用mysql库 use mysql; ## 修改user表中的Host,% 代表任意的客户端,可替换成具体IP地址。 update user set Host='%' where User='root'; ? ## 刷新 flush privileges;
-----------------------------------错误解决方案如下---------------------------------------
[root@localhost yum.repos.d]# systemctl enable mysqld [root@localhost yum.repos.d]# cat /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid 修改数据库存放目录 [root@localhost yum.repos.d]# mkdir -p /opt/mysql/data 您在 /var/spool/mail/root 中有新邮件 [root@localhost yum.repos.d]# vi /etc/my.cnf [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# cd /var/lib/m machines/ ? ? ?misc/ ? ? ? ? ?mlocate/ ? ? ? mysql/ ? ? ? ? mysql-files/ ? mysql-keyring/ [root@localhost yum.repos.d]# cd /var/lib/mysql 您在 /var/spool/mail/root 中有新邮件 [root@localhost mysql]# ls [root@localhost mysql]# systemctl start mysqld ^C 您在 /var/spool/mail/root 中有新邮件 [root@localhost mysql]# ^C [root@localhost mysql]# ^C [root@localhost mysql]# systemctl status mysqld ● mysqld.service - MySQL Server ? ?Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) ? ?Active: activating (start-pre) since 一 2022-04-25 13:34:17 CST; 1min 57s ago ? ? ?Docs: man:mysqld(8) ? ? ? ? ? ?http://dev.mysql.com/doc/refman/en/using-systemd.html ? Control: 24343 (mysqld_pre_syst) ? ? Tasks: 28 ? ?CGroup: /system.slice/mysqld.service ? ? ? ? ? ?└─control ? ? ? ? ? ? ?├─24343 /bin/bash /usr/bin/mysqld_pre_systemd ? ? ? ? ? ? ?└─24373 /usr/sbin/mysqld --initialize --datadir=/opt/mysql/data --user=mysql --init-file=/var/lib/mysql-files/install-...
4月 25 13:34:17 localhost.localdomain systemd[1]: Starting MySQL Server... [root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log 2022-04-25T05:34:33.968404Z 1 [Note] A temporary password is generated for root@localhost: FKlYFfSM2q<! [root@localhost mysql]# mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 您在 /var/spool/mail/root 中有新邮件 [root@localhost mysql]# mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [root@localhost mysql]# systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
4月 25 13:39:24 localhost.localdomain systemd[1]: mysqld.service holdoff time over, scheduling restart. 4月 25 13:39:24 localhost.localdomain systemd[1]: Stopped MySQL Server. 4月 25 13:39:24 localhost.localdomain systemd[1]: Starting MySQL Server... [root@localhost mysql]# ?lsof -i:3306 [root@localhost mysql]# systemctl stop mysqld 您在 /var/spool/mail/root 中有新邮件 [root@localhost mysql]# systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [root@localhost mysql]# ?vi /var/log/mysqld.log 查看日志发现 1)错误 The innodb_system data file 'ibdata1' must be writable 字面意思:’ibdata1必须可写 那么解决方案自然是更改对应权限 通过yum安装的话, 5.7版本以前是 chmod -R 777 /usr/local/mysql/data/ 5.7版本以后是 chmod -R 777 /var/lib/mysql
如果不是通过yum安装的话: find / -name ibdata1 找到对应目录更改权限~ 2)警告 Can't create test file /opt/mysql/data/localhost.lower-test 第一,selinux,记得当年字符界面安装redhat(很古老的操作系统么。。。)的时候,有这么一个选项,通常都听取前辈的建议, 改变默认值以不安装它。但如果你恰好要操作的这台机器开着selinux,它确实能够使你的mysql无法在新目标位置进行mysql_install_db的操作, 并爆出标题所示的警告。一个简单的解决办法是使用命令暂时关闭selinux,以便让你的操作可以继续下去
setenforce 0
但最好使用一个永久方法,以便在重启后继续不要这货。 修改/etc/selinux/config文件中设置SELINUX=disabled ,然后重启或等待下次重启。
第二,apparmor,这个坑爹货和selinux一样的坑爹,它也对mysql所能使用的目录权限做了限制 在 /etc/apparmor.d/usr.sbin.mysqld 这个文件中,有这两行,规定了mysql使用的数据文件路径权限 /var/lib/mysql/ r, /var/lib/mysql/** rwk, /var/lib/mysql/就是之前mysql安装的数据文件默认路径,apparmor控制这里mysqld可以使用的目录的权限 把数据文件移动到/data/mysql下,那么为了使mysqld可以使用/data/mysql这个目录,照上面那两
[root@localhost mysql]# [root@localhost mysql]# [root@localhost mysql]# chmod -R 777 /opt/mysql/ [root@localhost mysql]# systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [root@localhost mysql]# systemctl stop mysqld [root@localhost mysql]# systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [root@localhost mysql]# ?vi /var/log/mysqld.log 您在 /var/spool/mail/root 中有新邮件 [root@localhost mysql]# [root@localhost mysql]# [root@localhost mysql]# [root@localhost mysql]# vi ?/etc/apparmor.d/usr.sbin.mysqld [root@localhost mysql]# cat ? /etc/apparmor.d cat: /etc/apparmor.d: 没有那个文件或目录 [root@localhost mysql]# cd ? /etc/apparmor.d -bash: cd: /etc/apparmor.d: 没有那个文件或目录 [root@localhost mysql]# ?vi /var/log/mysqld.log 您在 /var/spool/mail/root 中有新邮件 [root@localhost mysql]# [root@localhost mysql]# [root@localhost mysql]# setenforce 0 [root@localhost mysql]# systemctl start mysqld [root@localhost mysql]# ?lsof -i:3306 COMMAND ? PID ?USER ? FD ? TYPE ?DEVICE SIZE/OFF NODE NAME mysqld ?31934 mysql ? 21u ?IPv6 2943808 ? ? ?0t0 ?TCP *:mysql (LISTEN) [root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log 2022-04-25T05:34:33.968404Z 1 [Note] A temporary password is generated for root@localhost: FKlYFfSM2q<! [root@localhost mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. ?Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.37
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> SHOW VARIABLES LIKE 'validate_password%'; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> set password = password("111111"); ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql> set password = password("xx#123456"); ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql> set password = password("Xxx@#123456"); Query OK, 0 rows affected, 1 warning (0.03 sec)
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 Host='%' where User='root'; Query OK, 1 row affected (0.04 sec) Rows matched: 1 ?Changed: 1 ?Warnings: 0
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%'; +--------------------------------------+--------+ | Variable_name ? ? ? ? ? ? ? ? ? ? ? ?| Value ?| +--------------------------------------+--------+ | validate_password_check_user_name ? ?| OFF ? ?| | validate_password_dictionary_file ? ?| ? ? ? ?| | validate_password_length ? ? ? ? ? ? | 8 ? ? ?| | validate_password_mixed_case_count ? | 1 ? ? ?| | validate_password_number_count ? ? ? | 1 ? ? ?| | validate_password_policy ? ? ? ? ? ? | MEDIUM | | validate_password_special_char_count | 1 ? ? ?| +--------------------------------------+--------+ 7 rows in set (0.00 sec)
mysql> ?
|