[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# rpm -qa | grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
[root@localhost ~]# ps -ef | grep mysql
root 4478 4237 0 12:12 pts/2 00:00:00 grep mysql
[root@localhost ~]# service mysqld stop
Stopping mysqld: [ OK ]
[root@localhost ~]# rpm -e mysql-libs-5.1.73-8.el6_8.x86_64 --nodeps
参数选项:
rpm -e mysql 普通删除模式
rpm -e --nodeps 强力删除模式,如果使用上面命令删除时,提示有依赖的其他文件,则用该命令可以对其进行强力删除。
MySQL软件库依次安装如下:
[root@localhost ~]# cd /home/Software/MySQL/
[root@localhost MySQL]# ls
mysql-community-client-5.7.34-1.el7.x86_64.rpm
mysql-community-devel-5.7.34-1.el7.x86_64.rpm
mysql-community-server-5.7.34-1.el7.x86_64.rpm
mysql-community-common-5.7.34-1.el7.x86_64.rpm
mysql-community-libs-5.7.34-1.el7.x86_64.rpm
[root@localhost MySQL]# rpm -e mariadb-libs-1:5.5.68-1.el7.x86_64 --nodeps
[root@localhost MySQL]# sudo yum install -y mysql-community-common-5.7.34-1.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-common-5.7.34-1.el7.x86_64.rpm: mysql-community-common-5.7.34-1.el7.x86_64
Marking mysql-community-common-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-common.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
mysql-community-common x86_64 5.7.34-1.el7 /mysql-community-common-5.7.34-1.el7.x86_64 2.8 M
Transaction Summary
==================================================================================================================================================================
Install 1 Package
Total size: 2.8 M
Installed size: 2.8 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), ‘yum check‘ output follows:
icedtea-web-1.7.1-2.el7_6.x86_64 has missing requires of java-1.8.0-openjdk
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-9.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
Installing : mysql-community-common-5.7.34-1.el7.x86_64 1/1
Verifying : mysql-community-common-5.7.34-1.el7.x86_64 1/1
Installed:
mysql-community-common.x86_64 0:5.7.34-1.el7
Complete!
[root@localhost MySQL]# sudo yum install -y mysql-community-libs-5.7.34-1.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-libs-5.7.34-1.el7.x86_64.rpm: mysql-community-libs-5.7.34-1.el7.x86_64
Marking mysql-community-libs-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
mysql-community-libs x86_64 5.7.34-1.el7 /mysql-community-libs-5.7.34-1.el7.x86_64 9.5 M
Transaction Summary
==================================================================================================================================================================
Install 1 Package
Total size: 9.5 M
Installed size: 9.5 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-libs-5.7.34-1.el7.x86_64 1/1
Verifying : mysql-community-libs-5.7.34-1.el7.x86_64 1/1
Installed:
mysql-community-libs.x86_64 0:5.7.34-1.el7
Complete!
[root@localhost MySQL]# sudo yum install -y mysql-community-client-5.7.34-1.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-client-5.7.34-1.el7.x86_64.rpm: mysql-community-client-5.7.34-1.el7.x86_64
Marking mysql-community-client-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
mysql-community-client x86_64 5.7.34-1.el7 /mysql-community-client-5.7.34-1.el7.x86_64 102 M
Transaction Summary
==================================================================================================================================================================
Install 1 Package
Total size: 102 M
Installed size: 102 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-client-5.7.34-1.el7.x86_64 1/1
Verifying : mysql-community-client-5.7.34-1.el7.x86_64 1/1
Installed:
mysql-community-client.x86_64 0:5.7.34-1.el7
Complete!
[root@localhost MySQL]# sudo yum install -y mysql-community-server-5.7.34-1.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-server-5.7.34-1.el7.x86_64.rpm: mysql-community-server-5.7.34-1.el7.x86_64
Marking mysql-community-server-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
mysql-community-server x86_64 5.7.34-1.el7 /mysql-community-server-5.7.34-1.el7.x86_64 761 M
Transaction Summary
==================================================================================================================================================================
Install 1 Package
Total size: 761 M
Installed size: 761 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-server-5.7.34-1.el7.x86_64 1/1
Verifying : mysql-community-server-5.7.34-1.el7.x86_64 1/1
Installed:
mysql-community-server.x86_64 0:5.7.34-1.el7
Complete!
[root@localhost MySQL5.7]# sudo yum install -y mysql-community-devel-5.7.34-1.el7.x86_64.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-devel-5.7.34-1.el7.x86_64.rpm: mysql-community-devel-5.7.34-1.el7.x86_64
Marking mysql-community-devel-5.7.34-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-devel.x86_64 0:5.7.34-1.el7 will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
mysql-community-devel x86_64 5.7.34-1.el7 /mysql-community-devel-5.7.34-1.el7.x86_64 24 M
Transaction Summary
==================================================================================================================================================================
Install 1 Package
Total size: 24 M
Installed size: 24 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-devel-5.7.34-1.el7.x86_64 1/1
Verifying : mysql-community-devel-5.7.34-1.el7.x86_64 1/1
Installed:
mysql-community-devel.x86_64 0:5.7.34-1.el7
Complete!
[root@localhost ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2021-09-11 05:17:30 PDT; 2min 54s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 64164 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 64137 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 64167 (mysqld)
Tasks: 28
CGroup: /system.slice/mysqld.service
└─64167 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Sep 11 05:17:28 localhost.localdomain systemd[1]: Starting MySQL Server...
Sep 11 05:17:30 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost ~]# systemctl start mysqld
[root@localhost MySQL]# grep ‘temporary password‘ /var/log/mysqld.log
2021-09-11T12:12:38.597863Z 1 [Note] A temporary password is generated for root@localhost: Ik8r-W0FefUo
(特别说明:由于安装时自动生成了默认密码,所以登录前需要事先查找默认密码。默认密码为“:,rkTG:o7+0-”。如果提示找不到“mysqld.log”文件,则先执行“systemctl status mysqld”确认MySQL是否正常运行,如果未正常运行,则执行“systemctl start mysqld”,数据库初始化后,会自动生成“mysqld.log”文件)
mysql> set password for ‘root‘@‘localhost‘=password(‘Db0AdMiN1!‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)
(特别说明:新密码必须包含大小写字母、符号、数字)
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect=‘SET NAMES utf8‘
[root@localhost ~]# systemctl start mysqld
登录数据库(略)
查看修改编码
mysql> show variables like ‘%character%‘;
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
max_connections=200
[root@localhost ~]# systemctl restart mysqld
mysql> show variables like ‘%max_connections%‘;
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 rows in set (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘luxus‘@‘%‘ IDENTIFIED BY ‘Db0AdMiN1!‘ WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(特别说明:luxus为新用户名,Db0AdMiN1!为新密码)
mysql> use mysql;
Database changed
mysql> update user set host="%" where user="root";
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | luxus |
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
4 rows in set (0.00 sec)
(特别说明:如果这些配置都做完了,还是无法远程访问数据库,这个时候可以检查一下Linux服务器的防火墙是否已关闭,如防火墙已开启,则关闭即可)
[root@localhost ~]# systemctl disable firewalld
MySQL 5.7数据库安装成功后,默认已设置为自启动。
lower_case_table_names=1(0:区分大小写;1:不区分大小写);
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
lower_case_table_names=1
[root@localhost ~]# systemctl restart mysqld
mysql> show variables like ‘%case%‘;
+------------------------------------+-------+
| Variable_name | Value |
+------------------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
| validate_password_mixed_case_count | 1 |
+------------------------------------+-------+
3 rows in set (0.00 sec)
mysql> update user set authentication_string=password(‘Db0AdMiN1!13‘) where user=‘luxus‘ and host=‘%‘;
Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
port=3306
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
skip-name-resolve
[root@localhost ~]# systemctl restart mysqld
(特别说明:如果远程连接数据库较慢,可禁用MySQL数据库DNS自动扫描)
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl restart mysqld
[root@localhost MySQL5.7]# mysql -V
mysql Ver 14.14 Distrib 5.7.34, for Linux (x86_64) using EditLine wrapper
(特别说明:V是大写)
[root@localhost ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2021-09-11 05:17:30 PDT; 2min 54s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 64164 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 64137 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 64167 (mysqld)
Tasks: 28
CGroup: /system.slice/mysqld.service
└─64167 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Sep 11 05:17:28 localhost.localdomain systemd[1]: Starting MySQL Server...
Sep 11 05:17:30 localhost.localdomain systemd[1]: Started MySQL Server
[root@localhost MySQL]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.31
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> exit;
Bye
暂无。
[root@localhost ~]# rpm -qa | grep jdk
jdk-11.0.12-11.0.12-ga.x86_64
[root@localhost ~]# rpm -e jdk-11.0.12-11.0.12-ga.x86_64 --nodeps
参数选项:
rpm -e jdk 普通删除模式
rpm -e --nodeps 强力删除模式,如果使用上面命令删除时,提示有依赖的其他文件,则 用该命令可以对其进行强力删除。
[root@localhost ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@localhost JDK]# find / -name mysql
find: ‘/run/user/1000/gvfs’: Permission denied
/etc/logrotate.d/mysql
/etc/selinux/targeted/active/modules/100/mysql
/etc/selinux/targeted/tmp/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/usr/share/mysql
/usr/include/mysql
/usr/include/mysql/mysql
[root@localhost ~]# which mysql
/usr/bin/mysql
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/var/lib
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@localhost ~]# vim /var/log/mysqld.log
2021-09-11T12:12:37.022281Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-11T12:12:37.414566Z 0 [Warning] InnoDB: New log files created, LSN=45790
...
问题原因:由于CentOS 7.9内置组件“mariadb-libs-1:5.5.68-1.el7.x86_64”与“mysql-community-common-5.7.34-1.el7.x86_64.rpm”存在包冲突,所以安装前先卸载。
解决方案:
[root@localhost MySQL]# rpm -e mariadb-libs-1:5.5.68-1.el7.x86_64 --nodeps
问题原因:那可能是系统防火墙打开了,关闭即可。
解决方案:
[root@localhost ~]# systemctl disable firewalld
问题原因:那可能远程连接自动扫描DNS,禁用即可。
解决方案:
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
skip-name-resolve
[root@localhost ~]# systemctl restart mysqld
原文:https://www.cnblogs.com/luxussss/p/15335465.html