mysql-5.7.22 主从同步

MySQL5.7安装与主从复制配置
本文介绍MySQL5.7的安装步骤及密码策略调整方法,并详细讲解了如何配置MySQL主从复制,包括主库和从库的设置。
部署运行你感兴趣的模型镜像

1.安装MySQL

1.1 更换源指定安装版本

wgethttp://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

yumlocalinstall mysql57-community-release-el7-8.noarch.rpm

yum repolist enabled | grep"mysql.*-community.*"

1.2 安装MySQL

yum install mysql-community-server

1.3 开启数据库,并找到指定密码登录,创建账号

systemctl start mysqld
grep 'temporary password' /var/log/mysqld.log  #初始密码
mysql -uroot -p
mysql>create user root;
mysql>grant all privileges on *.* to root@'%' identified by 'Juzi@2018';
mysql>flush peivileges;
mysql>exit
mysql -uroot -pJuzi@123  #重新登录

1.4 mysql5.7账号密码登录优化

在安装完成mysql5.7之后.登录会默认修改密码,修改密码过程中可能会报错,myslq5.7对密码有一定要求

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements  
#报错  这个其实与validate_password_policy的值有关
validate_password_policy有以下取值:
PolicyTests Performed
0 or LOWLength
1 or MEDIUMLength; numeric, lowercase/uppercase, and special characters
2 or STRONGLength; numeric, lowercase/uppercase, and special characters; dictionary file

默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。

有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为123456。

必须修改两个全局参数:

首先,修改validate_password_policy参数的值

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

这样,判断密码的标准就基于密码的长度了。这个由validate_password_length参数来决定

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          8 |
+----------------------------+
1 row in set (0.00 sec)

validate_password_length参数默认为8,它有最小值的限制,最小值为:

validate_password_number_count
+ validate_password_special_char_count
+ (2 * validate_password_mixed_case_count)

其中,validate_password_number_count指定了密码中数据的长度,validate_password_special_char_count指定了密码中特殊字符的长度,validate_password_mixed_case_count指定了密码中大小字母的长度。

这些参数,默认值均为1,所以validate_password_length最小值为4,如果你显性指定validate_password_length的值小于4,尽管不会报错,但validate_password_length的值将设为4。如下所示:

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          8 |
+----------------------------+
1 row in set (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          4 |
+----------------------------+
1 row in set (0.00 sec)

如果修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一个值,则validate_password_length将进行动态修改。

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          4 |
+----------------------------+
row in set (0.00 sec)

mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
|                                    1 |
+--------------------------------------+
row in set (0.00 sec)

mysql> set global validate_password_mixed_case_count=2;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
|                                    2 |
+--------------------------------------+
row in set (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
|                          6 |
+----------------------------+
row in set (0.00 sec)

当然,前提是validate_password插件必须已经安装,MySQL5.7是默认安装的。

那么如何验证validate_password插件是否安装呢?可通过查看以下参数,如果没有安装,则输出将为空。

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_dictionary_file    |       |
| validate_password_length             | 6     |
| validate_password_mixed_case_count   | 2     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
6 rows in set (0.00 sec

2.搭建主从

2.1修改主库配置文件

[root@5haocentos ~]# cat /etc/my.cnf
[mysqld]
server-id=1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
port=33080
log-bin=mysql-bin
log-bin-index=master-bin.index
binlog_format=mixed
binlog-do-db=bgy
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
#密码永久不过期配置
default_password_lifetime=0
#skip-grant-tables
symbolic-links=0


log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
pid-file=/var/lib/mysql/mysqld.pid
wait_timeout=31536000
interactive_timeout=31536000

2.2登录创建备份账号 锁表

mysql>create user backup;
mysql>grant all privileges on *.* to 'backup'@'192.168.0.%' identified by 'Yuan@123';
mysql>flush privileges;
mysql>flush tables with read lock;  #锁表

2.3修改从库配置文件

[root@6haocentos ~]# cat /etc/my.cnf
[mysqld]
server-id=2
log-bin=mysql-bin
binlog_format=mixed
relay-log=slave-relay-bin
relay-log-index=slave-relay-bin.index
binlog-do-db=bgy
replicate_wild_ignore_table=mysql.%
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
port=33080
innodb_checksum_algorithm=innodb




symbolic-links=0


log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

2.4在从库上配置主库信息(根据个人设置 )

mysql> reset maste;
mysql> change master to master_host='192.168.0.5',master_user='backup',master_password='****',master_log_file='mysql-bin.000006',master_log_pos='154',master_port=3306;

2.5主库解锁

unlock tables

2.6开启主从 查看状态

mysql> start slave;
mysql>show slave status\G;

若出现


则主从搭建完成

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

[root@lumingdong tool]# rpm -ivh mysql-community-common-*.rpm warning: mysql-community-common-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] package mysql-community-common-5.7.22-1.el7.x86_64 is already installed [root@lumingdong tool]# rpm -ivh mysql-community-libs-*.rpm warning: mysql-community-libs-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] package mysql-community-libs-5.7.22-1.el7.x86_64 is already installed [root@lumingdong tool]# rpm -ivh mysql-community-client-*.rpm warning: mysql-community-client-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] package mysql-community-client-5.7.22-1.el7.x86_64 is already installed [root@lumingdong tool]# rpm -ivh mysql-community-server-*.rpm warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] file /usr/bin/mysql from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-client-5.7.22-1.el7.x86_64 file /usr/bin/mysqladmin from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-client-5.7.22-1.el7.x86_64 file /usr/bin/mysqldump from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-client-5.7.22-1.el7.x86_64 file /usr/bin/mysqlpump from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-client-5.7.22-1.el7.x86_64 file /etc/my.cnf from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/my_print_defaults from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /var/lib/mysql from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/mysql_install_db from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/mysql_ssl_rsa_setup from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/mysql_tzinfo_to_sql from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/mysql_upgrade from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/adt_null.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/auth_socket.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/authentication_ldap_sasl_client.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/connection_control.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/group_replication.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/innodb_engine.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/keyring_file.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/keyring_udf.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/libmemcached.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/locking_service.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mypluglib.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mysql_no_login.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mysqlx.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/rewrite_example.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/rewriter.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/semisync_master.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/semisync_slave.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/validate_password.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/version_token.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/sbin/mysqld from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 package mysql-community-server-5.7.22-1.el7.x86_64 is already installed file /etc/my.cnf conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/my_print_defaults conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/mysql_install_db conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/mysql_ssl_rsa_setup conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/mysql_tzinfo_to_sql conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/mysql_upgrade conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/adt_null.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/auth_socket.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/authentication_ldap_sasl_client.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/connection_control.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/group_replication.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/innodb_engine.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/keyring_file.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/keyring_udf.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/libmemcached.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/locking_service.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mypluglib.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mysql_no_login.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mysqlx.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/rewrite_example.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/rewriter.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/semisync_master.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/semisync_slave.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/validate_password.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/version_token.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/sbin/mysqld conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /var/lib/mysql conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 [root@lumingdong tool]# chown -R mysql:mysql /var/log/mysqld.logchown -R mysql:mysql /var/log/mysqld.log chown: cannot access ‘/var/log/mysqld.logchown’: No such file or directory chown: cannot access ‘mysql:mysql’: No such file or directory [root@lumingdong tool]# chmod 755 /var/log/mysqld.log [root@lumingdong tool]# systemctl start mysqld Failed to get D-Bus connection: No such file or directory [root@lumingdong tool]#
08-15
<think>我们正在处理在Linux子系统(如WSL)中安装MySQL 5.7.22 RPM包时出现的冲突和签名警告,以及安装后无法启动mysqld服务的问题。根据用户提供的上下文,我们已知以下信息: - 用户有一个包含多个RPM包的目录,包括`mysql-community-common`、`mysql-community-libs`等。 - 安装过程中可能遇到依赖冲突(如与mariadb-libs的冲突)和签名警告(GPG签名验证失败)。 - 安装后无法启动mysqld服务,可能是由于权限问题或初始化失败。 我们将按照以下步骤解决: 1. 解决依赖冲突(特别是mariadb-libs)。 2. 处理GPG签名警告。 3. 按正确顺序安装RPM包。 4. 初始化MySQL并启动服务,处理可能出现的权限问题。 注意:在Linux子系统中,尤其是WSL1,systemd可能不被支持,因此我们使用传统的service命令。 具体步骤: ### 步骤1: 解决依赖冲突(mariadb-libs) 在安装MySQL之前,需要移除系统上可能存在的冲突包(如mariadb-libs)。使用以下命令: ```bash yum remove mariadb-libs --nodeps ``` `--nodeps`选项表示忽略依赖关系强制卸载,但需谨慎使用,因为可能破坏其他软件依赖。但在纯净的Linux子系统中,通常不会影响其他关键软件。 ### 步骤2: 处理GPG签名警告 在安装RPM包时,可能会遇到GPG签名验证失败。可以通过导入MySQL的GPG密钥来解决: ```bash rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql ``` 或者在安装时跳过签名检查(不推荐,但在测试环境中可以使用): ```bash rpm -ivh --nodeps --force mysql-community-*.rpm ``` 但更安全的方式是导入密钥后正常安装。 ### 步骤3: 按顺序安装RPM包 必须按照依赖顺序安装,否则会失败。参考[^1][^2]中的顺序: ```bash rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm ``` 如果出现依赖错误,可以尝试使用`--nodeps`选项(但后续可能还需要安装其他依赖,如`libaio`、`numactl`等): ```bash yum install libaio numactl ``` ### 步骤4: 初始化MySQL并启动服务 安装完成后,需要初始化MySQL数据目录并启动服务: ```bash # 初始化数据库(生成初始root密码) mysqld --initialize --user=mysql # 确保数据目录权限正确 chown -R mysql:mysql /var/lib/mysql # 启动mysqld服务 service mysqld start # 或者使用 systemctl start mysqld(如果支持) # 查看服务状态 service mysqld status ``` ### 步骤5: 获取临时密码并登录 初始化后,MySQL会生成一个临时密码,位于日志文件中: ```bash grep 'temporary password' /var/log/mysqld.log ``` 使用该密码登录并修改root密码: ```bash mysql -u root -p ``` 在MySQL中执行: ```sql ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码'; ``` 注意:新密码必须符合密码策略(至少8位,包含大小写字母、数字和特殊字符)。如果希望使用简单密码,可以先修改策略: ```sql SET GLOBAL validate_password_policy=LOW; SET GLOBAL validate_password_length=4; ALTER USER 'root'@'localhost' IDENTIFIED BY '简单密码'; ``` ### 步骤6: 设置开机启动(可选) ```bash chkconfig mysqld on # 对于SysV系统 # 或者 systemctl enable mysqld # 对于systemd系统 ``` ### 常见问题及解决 1. **启动失败**:检查`/var/log/mysqld.log`中的错误信息。常见错误包括: - 数据目录权限问题:确保`/var/lib/mysql`的所有者是mysql用户(`chown -R mysql:mysql /var/lib/mysql`)。 - 端口冲突:确保3306端口没有被其他程序占用。 - 内存不足:MySQL初始化需要一定内存,如果子系统内存不足,尝试增加内存或使用交换空间。 2. **SELinux问题**:如果系统启用了SELinux,可能导致权限问题。可以临时禁用SELinux: ```bash setenforce 0 ``` 或者永久禁用:修改`/etc/selinux/config`,设置`SELINUX=permissive`。 3. **WSL中systemd支持问题**:WSL默认不使用systemd,因此`systemctl`命令可能无效。可以使用以下方法启动服务: ```bash /etc/init.d/mysqld start # 使用SysV脚本启动 ``` 或者安装systemd替代方案(如genie)[^4]。 ### 总结 通过以上步骤,应该能够解决在Linux子系统中安装MySQL 5.7.22时遇到的依赖冲突、签名验证和启动失败问题。关键点包括: - 移除冲突的mariadb-libs包。 - 导入GPG密钥或跳过签名检查。 - 按顺序安装RPM包并安装必要依赖。 - 初始化数据库并正确设置权限。 - 根据日志排查启动失败原因。 §§相关问题§§ 1. 如何在WSL中启用systemd支持以使用systemctl命令? 2. 如何调整MySQL的密码策略以允许简单密码? 3. 如何解决MySQL启动时的“无法绑定端口”错误? 4. 如何配置MySQL的远程访问权限? [^1]: mysql-linux安装教程。 [^2]: 解包mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar得到多个RPM包。 [^3]: MySQL 5.7 RPM包的下载地址。 [^4]: mysql5.7.22安装步骤。</think>### 解决Linux子系统下MySQL 5.7.22安装问题 #### 步骤1: 解决依赖冲突和签名警告 ```bash # 1. 强制移除冲突的mariadb-libs yum remove mariadb-libs.x86_64 --nodeps # 2. 导入MySQL GPG密钥解决签名警告 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 # 3. 按顺序安装核心组件 rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm ``` > **关键点**:必须按此顺序安装,否则会出现依赖错误[^1][^2] #### 步骤2: 修复mysqld服务启动失败 ```bash # 1. 修复数据目录权限 mkdir -p /var/lib/mysql chown -R mysql:mysql /var/lib/mysql # 2. 初始化数据库(生成临时root密码) mysqld --initialize --user=mysql # 3. 修复日志文件权限 chown mysql:mysql /var/log/mysqld.log chmod 660 /var/log/mysqld.log # 4. 启动服务 systemctl start mysqld ``` #### 步骤3: 获取初始密码并重置 ```bash # 1. 查看生成的临时密码 grep 'temporary password' /var/log/mysqld.log # 2. 使用临时密码登录 mysql -u root -p # 3.MySQL中重置密码 ALTER USER 'root'@'localhost' IDENTIFIED BY '您的新密码'; # 4. 降低密码策略强度(可选) SET GLOBAL validate_password_policy=LOW; ``` #### 步骤4: 验证安装 ```bash # 检查服务状态 systemctl status mysqld # 测试连接 mysql -u root -p -e "SELECT VERSION();" ``` ### 常见问题解决方案 1. **文件权限错误**: ```bash chown -R mysql:mysql /var/lib/mysql chmod 750 /var/lib/mysql ``` 2. **端口冲突**: ```bash netstat -tuln | grep 3306 # 若端口被占用,修改/etc/my.cnf中的端口号 ``` 3. **SELinux阻止**: ```bash setenforce 0 # 临时关闭 # 或修改/etc/selinux/config永久关闭 ``` 4. **WSL特殊问题**: ```bash # 手动启动服务(适用于WSL1) /usr/sbin/mysqld --user=mysql & ``` > **重要提示**:安装完成后立即从日志中获取临时密码,否则重启后可能丢失访问权限[^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值