阿里云CentOs服务器 安装与配置mysql数据库

阿里云CentOs服务器 安装与配置mysql数据库

以上为Linux安装mysql数据库

Linux 安装mysql 数据库

一下为mysql 安装教程




 
Using username "root".
Last login: Tue Oct  8 09:30:34 2019 from 113.98.245.93

Welcome to Alibaba Cloud Elastic Compute Service !

 [root@lwh ~]# yum  list installed mysql*
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
错误:没有匹配的软件包可以列出
[root@lwh ~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
已加载插件:fastestmirror, langpacks
无法打开 mysql57-community-release-el7-8.noarch.rpm ,跳过。
无须任何处理
[root@lwh ~]# cd /root
[root@lwh ~]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.                                                                                        rpm
--2019-10-08 09:40:16--  http://repo.mysql.com/mysql57-community-release-el7-8.n                                                                                        oarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 104.127.195.16
正在连接 repo.mysql.com (repo.mysql.com)|104.127.195.16|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9116 (8.9K) [application/x-redhat-package-manager]
正在保存至: “mysql57-community-release-el7-8.noarch.rpm”

100%[======================================>] 9,116       --.-K/s 用时 0s

2019-10-08 09:40:16 (118 MB/s) - 已保存 “mysql57-community-release-el7-8.noarch.                                                                                        rpm” [9116/9116])

[root@lwh ~]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql57-community-release-el7-8  ################################# [100%]
[root@lwh ~]# cd /etc/yum.repos.d/
[root@lwh yum.repos.d]# ls
CentOS-Base.repo       CentOS-Media.repo    mysql-community.repo
CentOS-CR.repo         CentOS-Sources.repo  mysql-community-source.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo
CentOS-fasttrack.repo  epel.repo
[root@lwh yum.repos.d]# yum install mysql-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
mysql-connectors-community                               | 2.5 kB     00:00
mysql-tools-community                                    | 2.5 kB     00:00
mysql57-community                                        | 2.5 kB     00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.7.27-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.7.27-1.el7,它被软件包 m                                                                                        ysql-community-server-5.7.27-1.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-c                                                                                        ommunity-server-5.7.27-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.7.27-1.el7 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.7.9,它被软件包 mysql-com                                                                                        munity-client-5.7.27-1.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.7.27-1.el7 将被 安装
--> 正在检查事务
---> 软件包 mysql-community-libs.x86_64.0.5.7.27-1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package                   架构      版本            源                    大小
================================================================================
正在安装:
 mysql-community-server    x86_64    5.7.27-1.el7    mysql57-community    165 M
为依赖而安装:
 mysql-community-client    x86_64    5.7.27-1.el7    mysql57-community     24 M
 mysql-community-common    x86_64    5.7.27-1.el7    mysql57-community    275 k
 mysql-community-libs      x86_64    5.7.27-1.el7    mysql57-community    2.2 M

事务概要
================================================================================
安装  1 软件包 (+3 依赖软件包)

总下载量:192 M
安装大小:865 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): mysql-community-common-5.7.27-1.el7.x86_64.rpm      | 275 kB   00:00
(2/4): mysql-community-libs-5.7.27-1.el7.x86_64.rpm        | 2.2 MB   00:00
(3/4): mysql-community-client-5.7.27-1.el7.x86_64.rpm      |  24 MB   00:02
(4/4): mysql-community-server-5.7.27-1.el7.x86_64.rpm                                                                                            | 165 MB  00:00:47
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                    4.0 MB/s | 192 MB  00:00:48
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
** 发现 1 个已存在的 RPM 数据库问题, 'yum check' 输出如下:
python-requests-2.6.0-5.el7.noarch 有缺少的需求 python-urllib3 >= ('0', '1.10.2', '1')
  正在安装    : mysql-community-common-5.7.27-1.el7.x86_64                                                                                                          1/4
  正在安装    : mysql-community-libs-5.7.27-1.el7.x86_64                                                                                                            2/4
  正在安装    : mysql-community-client-5.7.27-1.el7.x86_64                                                                                                          3/4
  正在安装    : mysql-community-server-5.7.27-1.el7.x86_64                                                                                                          4/4
  验证中      : mysql-community-client-5.7.27-1.el7.x86_64                                                                                                          1/4
  验证中      : mysql-community-common-5.7.27-1.el7.x86_64                                                                                                          2/4
  验证中      : mysql-community-libs-5.7.27-1.el7.x86_64                                                                                                            3/4
  验证中      : mysql-community-server-5.7.27-1.el7.x86_64                                                                                                          4/4

已安装:
  mysql-community-server.x86_64 0:5.7.27-1.el7

作为依赖被安装:
  mysql-community-client.x86_64 0:5.7.27-1.el7            mysql-community-common.x86_64 0:5.7.27-1.el7            mysql-community-libs.x86_64 0:5.7.27-1.el7

完毕!
[root@lwh yum.repos.d]# mysql -V
mysql  Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using  EditLine wrapper
[root@lwh yum.repos.d]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@lwh yum.repos.d]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor prese                                                                                        t: disabled)
   Active: active (running) since 二 2019-10-08 09:53:29 CST; 12s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1397 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysql                                                                                        d/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 1291 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/                                                                                        SUCCESS)
 Main PID: 1400 (mysqld)
    Tasks: 27
   CGroup: /system.slice/mysqld.service
           └─1400 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys...

10月 08 09:53:21 lwh systemd[1]: Starting MySQL Server...
10月 08 09:53:29 lwh systemd[1]: Started MySQL Server.
[root@lwh yum.repos.d]# grep "password" /var/log/mysqld.log
2019-09-27T02:54:37.514492Z 1 [Note] A temporary password is generated for root@                                                                                        localhost: dM/+;gxtx5u&
2019-09-27T02:56:51.941440Z 2 [Note] Access denied for user 'root'@'localhost' (                                                                                        using password: YES)
2019-09-27T07:13:29.544662Z 0 [Note] Shutting down plugin 'validate_password'
2019-09-27T07:13:30.919751Z 0 [Note] Shutting down plugin 'sha256_password'
2019-09-27T07:13:30.919754Z 0 [Note] Shutting down plugin 'mysql_native_passwor                                                                                         '
2019-09-27T07:14:15.493803Z 0 [Note] Shutting down plugin 'validate_password'
2019-09-27T07:14:16.901327Z 0 [Note] Shutting down plugin 'sha256_password'
2019-09-27T07:14:16.901330Z 0 [Note] Shutting down plugin 'mysql_native_passwor                                                                                         '
2019-09-27T07:17:53.235441Z 0 [Note] Shutting down plugin 'validate_password'
2019-09-27T07:17:54.481004Z 0 [Note] Shutting down plugin 'sha256_password'
2019-09-27T07:17:54.481008Z 0 [Note] Shutting down plugin 'mysql_native_passwor                                                                                         '
2019-09-27T07:19:43.334368Z 2 [Note] Access denied for user 'root'@'localhost' (                                                                                        using password: NO)
2019-09-27T07:24:01.586076Z 3 [Note] Access denied for user 'root'@'localhost' (                                                                                        using password: YES)
2019-09-27T07:38:25.108093Z 0 [Note] Shutting down plugin 'validate_password'
2019-09-27T07:38:26.832129Z 0 [Note] Shutting down plugin 'sha256_password'
2019-09-27T07:38:26.832133Z 0 [Note] Shutting down plugin 'mysql_native_passwor                                                                                         '
2019-09-27T07:44:06.256534Z 3 [Note] Access denied for user 'root'@'localhost' (                                                                                        using password: NO)
2019-09-27T08:20:25.906079Z 2 [Warning] Plugin validate_password reported: 'Effe                                                                                        ctive value of validate_password_length is changed. New value is 4'
2019-09-29T01:17:21.691602Z 4 [Note] Access denied for user 'root'@'localhost' (                                                                                        using password: YES)
2019-09-29T02:57:47.686866Z 0 [Note] Shutting down plugin 'validate_password'
2019-09-29T02:57:49.286496Z 0 [Note] Shutting down plugin 'sha256_password'
2019-09-29T02:57:49.286499Z 0 [Note] Shutting down plugin 'mysql_native_passwor                                                                                         '
2019-10-08T01:53:25.842666Z 1 [Note] A temporary password is generated for root@                                                                                        localhost: jN2+I2R8KiIk
[root@lwh yum.repos.d]# mysql -uroot -p'jN2+I2R8KiIk'
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.27

Copyright (c) 2000, 2019, 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>
mysql> SET PASSWORD = PASSWORD('passw0rd');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD = PASSWORD('passw0rd'); --设定mysql密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;  --设定用户下的密码永久生效,不过期
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;   --以上命令即时生效
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to root@"%" identified by "passw0rd";   --允许其他任意机主登录mysql数据库
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to root@"localhost" identified by "passw0rd";  --允许其他任意主机登录mysql数据库
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql
> flush privileges;
Query OK,
0 rows affected (0.00 sec)

mysql
>

 以上安装mysql之后,发现并不能连接服务器中的mysql,原因是:云服务器并没有开放mysql的3306端口

第一步:

第二步:

 第三步:

第四步:

第五步:

在阿里云上配置端口之后即可使用。

猜你喜欢

转载自www.cnblogs.com/liuwenhao-1/p/11635916.html