linux上安装MySQL

1)卸载mariadb

rpm -qa | grep mariadb | xargs rpm -e --nodeps

2)下载msql5.7 yum源

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

3)安装yum源

rpm -ivh mysql57-community-release-el7-9.noarch.rpm

4)安装mysql

yum -y install mysql-server

5)启动mysql

service mysqld start

6)查看root用户密码

grep 'temporary password' /var/log/mysqld.log    d9V,K1..6e.Q

7)执行mysql初始化脚本

mysql_secure_installation

8)配置root用户远程访问权限

mysql> grant all privileges on *.* to 'root' @'%' identified by 'xinmima';

mysql> flush privileges;
rpm -qa | grep mariadb | xargs rpm -e --nodeps
rpm: no packages given for erase
[root@VM-0-13-centos ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
--2020-09-26 22:54:39--  https://dev.mysql.com/get/mysql57-community-release-el7-9.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-9.noarch.rpm [following]
--2020-09-26 22:54:41--  https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.1.245.43
Connecting to repo.mysql.com (repo.mysql.com)|23.1.245.43|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’

100%[============================================================================================================================>] 9,224       --.-K/s   in 0s      

2020-09-26 22:54:42 (102 MB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved [9224/9224]

[root@VM-0-13-centos ~]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm
warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-9  ################################# [100%]
[root@VM-0-13-centos ~]# yum -y install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel                                                                                                                                           | 4.7 kB  00:00:00     
extras                                                                                                                                         | 2.9 kB  00:00:00     
mysql-connectors-community                                                                                                                     | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                          | 2.5 kB  00:00:00     
mysql57-community                                                                                                                              | 2.5 kB  00:00:00     
os                                                                                                                                             | 3.6 kB  00:00:00     
updates                                                                                                                                        | 2.9 kB  00:00:00     
(1/3): mysql-tools-community/x86_64/primary_db                                                                                                 |  76 kB  00:00:03     
(2/3): mysql57-community/x86_64/primary_db                                                                                                     | 224 kB  00:00:03     
(3/3): mysql-connectors-community/x86_64/primary_db                                                                                            |  62 kB  00:00:05     
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.31-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.31-1.el7 for package: mysql-community-server-5.7.31-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.31-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.31-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.31-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.31-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.31-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================================
 Package                                        Arch                           Version                                Repository                                 Size
======================================================================================================================================================================
Installing:
 mysql-community-server                         x86_64                         5.7.31-1.el7                           mysql57-community                         173 M
Installing for dependencies:
 mysql-community-client                         x86_64                         5.7.31-1.el7                           mysql57-community                          25 M
 mysql-community-common                         x86_64                         5.7.31-1.el7                           mysql57-community                         311 k
 mysql-community-libs                           x86_64                         5.7.31-1.el7                           mysql57-community                         2.3 M

Transaction Summary
======================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 201 M
Installed size: 875 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.31-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY2 ETA 
Public key for mysql-community-common-5.7.31-1.el7.x86_64.rpm is not installed
(1/4): mysql-community-common-5.7.31-1.el7.x86_64.rpm                                                                                          | 311 kB  00:00:04     
(2/4): mysql-community-libs-5.7.31-1.el7.x86_64.rpm                                                                                            | 2.3 MB  00:00:47     

mysql-community-server-5.7.31-1.el7.x86_64.rpm                                                                                                 | 173 MB  00:28:59     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-9.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-7.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-7.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
  Installing : mysql-community-common-5.7.31-1.el7.x86_64                                                                                                         1/4 
  Installing : mysql-community-libs-5.7.31-1.el7.x86_64                                                                                                           2/4 
  Installing : mysql-community-client-5.7.31-1.el7.x86_64                                                                                                         3/4 
  Installing : mysql-community-server-5.7.31-1.el7.x86_64                                                                                                         4/4 
  Verifying  : mysql-community-client-5.7.31-1.el7.x86_64                                                                                                         1/4 
  Verifying  : mysql-community-libs-5.7.31-1.el7.x86_64                                                                                                           2/4 
  Verifying  : mysql-community-common-5.7.31-1.el7.x86_64                                                                                                         3/4 
  Verifying  : mysql-community-server-5.7.31-1.el7.x86_64                                                                                                         4/4 

Installed:
  mysql-community-server.x86_64 0:5.7.31-1.el7                                                                                                                        

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.31-1.el7           mysql-community-common.x86_64 0:5.7.31-1.el7           mysql-community-libs.x86_64 0:5.7.31-1.el7          

Complete!

[root@VM-0-13-centos ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@VM-0-13-centos ~]# grep 'temporary password' /var/log/mysqld.log 
2020-09-27T12:52:51.825767Z 1 [Note] A temporary password is generated for root@localhost: gc)yRGl7/c1X
[root@VM-0-13-centos ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 
Sorry, passwords do not match.

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
[root@VM-0-13-centos ~]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值