CentOS 7.2 64位 安装 MYSQL

之前记录过一次安装,今天新弄了个服务器结果按之前的教程又出问题了,仅仅可以参考了,最好还是去MYSQL官网按官方文档步骤操作
Linux7 安装 MYSQL
还有一篇设置root密码的,现在也有问题了最好还是安装下面的教程操作
Linux 安装 MYSQL 5.7 设置root密码

官网教程

官网文档地址

查看章节
2.5.1 Installing MySQL on Linux Using the MySQL Yum Repository
可以安装这个官方文档去做,这是比较稳妥的

首先下载一个很小的 ".rpm"文件
我下载的是 mysql57-community-release-el7-11.noarch.rpm
我上传在了root文件夹下面,当前就在root文件夹下操作的

1.Adding the MySQL Yum Repository

然后按教程上第一步是执行命令

sudo yum localinstall mysql57-community-release-el6-{version-number}.noarch.rpm

我这自然是

sudo yum localinstall mysql57-community-release-el7-11.noarch.rpm
2.Selecting a Release Series
yum repolist all | grep mysql
3.Installing MySQL
sudo yum install mysql-community-server

终端输出:

[root@VM_0_6_centos ~]# sudo yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
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
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.20-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.20-1.el7 for package: mysql-community-server-5.7.20-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.20-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.20-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.20-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.20-1.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.20-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================
 Package                                          Arch                             Version                                  Repository                                   Size
==============================================================================================================================================================================
Installing:
 mysql-community-server                           x86_64                           5.7.20-1.el7                             mysql57-community                           164 M
Installing for dependencies:
 mysql-community-client                           x86_64                           5.7.20-1.el7                             mysql57-community                            24 M
 mysql-community-common                           x86_64                           5.7.20-1.el7                             mysql57-community                           272 k
 mysql-community-libs                             x86_64                           5.7.20-1.el7                             mysql57-community                           2.1 M

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

Total download size: 190 M
Installed size: 857 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): mysql-community-server-5.7.20-1.el7.x86_64.rpm                                                                                                  | 164 MB  00:01:46
(2/2): mysql-community-client-5.7.20-1.el7.x86_64.rpm                                                                                                  |  24 MB  00:06:31
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                         490 kB/s | 188 MB  00:06:31
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.20-1.el7.x86_64                                                                                                                 1/4
  Installing : mysql-community-libs-5.7.20-1.el7.x86_64                                                                                                                   2/4
  Installing : mysql-community-client-5.7.20-1.el7.x86_64                                                                                                                 3/4
  Installing : mysql-community-server-5.7.20-1.el7.x86_64                                                                                                                 4/4
  Verifying  : mysql-community-libs-5.7.20-1.el7.x86_64                                                                                                                   1/4
  Verifying  : mysql-community-common-5.7.20-1.el7.x86_64                                                                                                                 2/4
  Verifying  : mysql-community-client-5.7.20-1.el7.x86_64                                                                                                                 3/4
  Verifying  : mysql-community-server-5.7.20-1.el7.x86_64                                                                                                                 4/4

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

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

Complete!
Starting the MySQL Server 启动
sudo service mysqld start
查看mysql状态
sudo 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 Wed 2017-11-15 11:39:47 CST; 57s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 32709 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 32620 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 32714 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─32714 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Nov 15 11:39:18 VM_0_6_centos systemd[1]: Starting MySQL Server...
Nov 15 11:39:47 VM_0_6_centos systemd[1]: Started MySQL Server.

修改初始密码

首先查看初始密码

初始密码在 /var/log/mysqld.log log文件中

sudo grep 'temporary password' /var/log/mysqld.log

终端输出了现在的初始密码:

2017-11-15T03:39:29.784737Z 1 [Note] A temporary password is generated for root@localhost: nee6r9?.bZDg

后面的 "nee6r9?.bZDg"就是现在的初始密码

修改root密码

登录
mysql -uroot -p

输入刚才的密码(复制粘贴即可)

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

这里注意密码要求:大写字母 小写字母 数字 特殊符号 构成哦

刷新系统列表

FLUSH PRIVILEGES;

退出

quit;

重启mysql

sudo service mysqld restart

可以用新密码试试了

设置MySQL远程访问

需求:需要在本地远程登录MySQL,采用的还是root用户+密码访问

服务器确保3306端口是可以访问的

配置服务器的安全组,入站规则中增加一条股则

0.0.0/0     TCP:3306  允许

将安全组配置在对应服务器上.

mysql 配置更改

修改配置文件

编辑 /etc/my.cnf
vim /etc/my.cnf

增加一行

bind-address = 0.0.0.0

我这是这样的:

   [mysqld]
   bind-address = 0.0.0.0

修改root用户

登录mysql

mysql -uroot -p

输入密码

mysql> use mysql;

mysql> select user,host from user;

   +---------------+-----------+
   | user          | host      |
   +---------------+-----------+
   | mysql.session | localhost |
   | mysql.sys     | localhost |
   | root          | localhost |
   +---------------+-----------+

将root用户host更新成 %:

    update user set host = '%' where user = 'root';

再查询看看:
mysql> select user,host from user;

    +---------------+-----------+
    | user          | host      |
    +---------------+-----------+
    | root          | %         |
    | mysql.session | localhost |
    | mysql.sys     | localhost |
    +---------------+-----------+
    3 rows in set (0.00 sec)

重启mysql
sudo service mysqld restart

搞定

你可能感兴趣的:(CentOS 7.2 64位 安装 MYSQL)