1、wget下载MySQL5.7rpm安装包
[root@localhost ~/Project]#wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm --2021-01-31 10:08:46-- https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11 Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm [following] --2021-01-31 10:08:47-- https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm Resolving repo.mysql.com (repo.mysql.com)... 104.86.185.42 Connecting to repo.mysql.com (repo.mysql.com)|104.86.185.42|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 25680 (25K) [application/x-redhat-package-manager] Saving to: ‘mysql57-community-release-el7-11.noarch.rpm’ 100%[====================================================================================================================================================================================================================================>] 25,680 157KB/s in 0.2s 2021-01-31 10:08:48 (157 KB/s) - ‘mysql57-community-release-el7-11.noarch.rpm’ saved [25680/25680] [root@localhost ~/Project]#
2、安装MySQL安装源
[root@localhost ~/Project]#yum -y localinstall mysql57-community-release-el7-11.noarch.rpm Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Examining mysql57-community-release-el7-11.noarch.rpm: mysql57-community-release-el7-11.noarch Marking mysql57-community-release-el7-11.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql57-community-release.noarch 0:el7-11 will be installed --> Finished Dependency Resolution base/x86_64 | 3.6 kB 00:00:00 epel/x86_64 | 4.7 kB 00:00:00 epel/x86_64/updateinfo | 1.0 MB 00:00:00 epel/x86_64/primary_db | 6.9 MB 00:00:00 extras/x86_64 | 2.9 kB 00:00:00 updates/x86_64 | 2.9 kB 00:00:00 Dependencies Resolved ============================================================================================================================================================================================================================================================================== Package Arch Version Repository Size ============================================================================================================================================================================================================================================================================== Installing: mysql57-community-release noarch el7-11 /mysql57-community-release-el7-11.noarch 31 k Transaction Summary ============================================================================================================================================================================================================================================================================== Install 1 Package Total size: 31 k Installed size: 31 k Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql57-community-release-el7-11.noarch 1/1 Verifying : mysql57-community-release-el7-11.noarch 1/1 Installed: mysql57-community-release.noarch 0:el7-11 Complete!
3、在线安装MySQL
[root@localhost ~/Project]#yum -y install mysql-community-server --nogpgcheck Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. mysql-connectors-community | 2.6 kB 00:00:00 mysql-tools-community | 2.6 kB 00:00:00 mysql57-community | 2.6 kB 00:00:00 (1/3): mysql-connectors-community/x86_64/primary_db | 72 kB 00:00:00 (2/3): mysql-tools-community/x86_64/primary_db | 85 kB 00:00:00 (3/3): mysql57-community/x86_64/primary_db | 258 kB 00:00:03 Resolving Dependencies --> Running transaction check ---> Package mariadb-server.x86_64 1:5.5.68-1.el7 will be obsoleted ---> Package mysql-community-server.x86_64 0:5.7.33-1.el7 will be obsoleting --> Processing Dependency: mysql-community-common(x86-64) = 5.7.33-1.el7 for package: mysql-community-server-5.7.33-1.el7.x86_64 --> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.33-1.el7.x86_64 --> Running transaction check ---> Package mariadb.x86_64 1:5.5.68-1.el7 will be obsoleted ---> Package mysql-community-client.x86_64 0:5.7.33-1.el7 will be obsoleting --> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.33-1.el7.x86_64 ---> Package mysql-community-common.x86_64 0:5.7.33-1.el7 will be installed --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be obsoleted --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-5.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: perl-DBD-MySQL-4.023-5.el7.x86_64 --> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64 ---> Package mysql-community-libs.x86_64 0:5.7.33-1.el7 will be obsoleting --> Running transaction check ---> Package mysql-community-libs-compat.x86_64 0:5.7.33-1.el7 will be obsoleting ---> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be updated ---> Package perl-DBD-MySQL.x86_64 0:4.023-6.el7 will be an update ---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated ---> Package postfix.x86_64 2:2.10.1-9.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved
4、设置开机自启动MySQL服务
[root@localhost ~/Project]#systemctl start mysqld [root@localhost ~/Project]#systemctl enable mysqld [root@localhost ~/Project]#systemctl daemon-reload
5、修改MySQL root登录密码
获取临时密码
[root@localhost ~/Project]#cat /var/log/mysqld.log | grep root@localhost 2021-01-31T01:04:29.718686Z 1 [Note] A temporary password is generated for root@localhost: qY?uY6NuW?3-
2. 使用临时密码登录MySQL[root@localhost ~/Project]#mysql -hlocalhost -uroot -P3306 -pqY?uY6NuW?3- 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.33 Copyright (c) 2000, 2021, 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>
3. 修改密码(要求密码至少为8位且必须为大小写字母数字特殊字母的组合)mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root1234@'; Query OK, 0 rows affected (0.00 sec)
6、设置允许远程登录
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root1234@' WITH GRANT OPTION; Query OK, 0 rows affected, 1 warning (0.01 sec)
7、退出
mysql> exit; Bye
8、配置MySQL默认编码为utf-8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置:
character_set_server=utf8 init_connect='SET NAMES utf8'
9、重启MySQL服务并登录MySQL验证编码
[root@localhost ~/Project]#systemctl restart mysqld [root@localhost ~/Project]#mysql -hlocalhost -uroot -P3306 -pRoot1234@ 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.33 MySQL Community Server (GPL) Copyright (c) 2000, 2021, 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 '%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.01 sec) mysql>