1. 从官网找到自己需要的mysql版本 我使用mysql5.7
这里有官方安装说明
或 使用 https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/ 链接
找到
获取这个链接
我使用的链接 http://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
2. 使用wget 获取rpm包
[root@VM_0_10_centos ~]# wget http://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
--2018-10-05 18:54:49-- http://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.2.3.81
Connecting to repo.mysql.com (repo.mysql.com)|23.2.3.81|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9116 (8.9K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-8.noarch.rpm’
100%[=============================================>] 9,116 --.-K/s in 0s
2018-10-05 18:54:49 (83.4 MB/s) - ‘mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116]
或参考官方指导 https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/#repo-qg-yum-installing
3. 安装 mysql community-release
[root@VM_0_10_centos ~]# yum -y install mysql57-community-release-el7-8.noarch.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
Marking mysql57-community-release-el7-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-8 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================
Package Arch Version
Repository Size
=======================================================================================
Installing:
mysql57-community-release noarch el7-8 /mysql57-community-release-el7-8.noarch 8.2 k
Transaction Summary
=======================================================================================
Install 1 Package
Total size: 8.2 k
Installed size: 8.2 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql57-community-release-el7-8.noarch 1/1
Verifying : mysql57-community-release-el7-8.noarch 1/1
Installed:
mysql57-community-release.noarch 0:el7-8
Complete!
4. 安装mysql 相关 服务
[root@VM_0_10_centos ~]# yum search mysql-com
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
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
(1/3): mysql57-community/x86_64/primary_db | 152 kB 00:00:00
(2/3): mysql-connectors-community/x86_64/primary_db | 26 kB 00:00:01
(3/3): mysql-tools-community/x86_64/primary_db | 45 kB 00:00:01
=============================== N/S matched: mysql-com ================================
mysql-community-client.i686 : MySQL database client applications and tools
mysql-community-client.x86_64 : MySQL database client applications and tools
mysql-community-common.i686 : MySQL database common files for server and client libs
mysql-community-common.x86_64 : MySQL database common files for server and client libs
mysql-community-devel.i686 : Development header files and libraries for MySQL database
: client applications
mysql-community-devel.x86_64 : Development header files and libraries for MySQL
: database client applications
mysql-community-embedded.i686 : MySQL embedded library
mysql-community-embedded.x86_64 : MySQL embedded library
mysql-community-embedded-compat.i686 : MySQL embedded compat library
mysql-community-embedded-compat.x86_64 : MySQL embedded compat library
mysql-community-embedded-devel.i686 : Development header files and libraries for MySQL
: as an embeddable library
mysql-community-embedded-devel.x86_64 : Development header files and libraries for
: MySQL as an embeddable library
mysql-community-libs.i686 : Shared libraries for MySQL database client applications
mysql-community-libs.x86_64 : Shared libraries for MySQL database client applications
mysql-community-libs-compat.i686 : Shared compat libraries for MySQL 5.6.25 database
: client applications
mysql-community-libs-compat.x86_64 : Shared compat libraries for MySQL 5.6.37 database
: client applications
mysql-community-release.noarch : MySQL repository configuration for yum
mysql-community-server.x86_64 : A very fast and reliable SQL database server
mysql-community-test.x86_64 : Test suite for the MySQL database server
Name and summary matches only, use "search all" for everything.
5. 安装 mysql 服务器
[root@VM_0_10_centos ~]# yum -y install mysql-community-server.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.23-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.23-1.el7 for package: mysql-community-server-5.7.23-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.23-1.el7.x86_64
。。。
。。。
。。。
省略
Dependency Installed:
mysql-community-client.x86_64 0:5.7.23-1.el7
mysql-community-common.x86_64 0:5.7.23-1.el7
numactl-libs.x86_64 0:2.0.9-7.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
6. 启动MySQL服务器
[root@VM_0_10_centos ~]# systemctl start mysqld.service
官方指导 7版本 启动服务器有区别
检查MySQL服务器的状态
[root@VM_0_10_centos ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2018-10-05 19:08:06 CST; 52s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 29471 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 29177 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 29474 (mysqld)
CGroup: /system.slice/mysqld.service
└─29474 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pi...
Oct 05 19:07:55 VM_0_10_centos systemd[1]: Starting MySQL Server...
Oct 05 19:08:06 VM_0_10_centos systemd[1]: Started MySQL Server.
显示为 Active: active (running) since Fri 2018-10-05 19:08:06 CST; 52s ago 代表正常启动
官方提示
7. 查看初始化密码
从MySQL 5.7开始 mysql会自动初始化一个密码 用户第一次登录 可在错误日志里查看
使用一下命令查看
[root@VM_0_10_centos ~]# grep 'temporary password' /var/log/mysqld.log
2018-10-05T11:07:57.372256Z 1 [Note] A temporary password is generated for root@localhost: :vqDKto/r1Vr
:vqDKto/r1Vr这是我的初始化密码(root@localhost: 后面)
8.使用初始化密码进入数据库
[root@VM_0_10_centos ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.23
Copyright (c) 2000, 2018, 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>
9.修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '简单密码';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '复杂密码';
Query OK, 0 rows affected (0.00 sec)
密码过于简单会修改失败
你以为 已经安好了么 那你可以远程连接一下试试看
使用远程链接会出现 1130 错误 (解决如下)
这是因为mysql 数据库 只对localhost 开启访问
10. 切换使用mysql数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
查看的user 表如下
mysql> select u.Host, u.User from user u;
+-----------+---------------+
| Host | User |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
可以看到root用户只对localhost开放
11. 修改root 用户对应的Host 为 % (把localhost 修改为 %)
mysql> update user u set u.Host = '%' where u.User = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
12.退出mysql重启 mysql服务即可完成安装
mysql> exit
Bye
[root@VM_0_10_centos ~]# systemctl restart mysqld.service
[root@VM_0_10_centos ~]#
13. 修改mysql默认编码为UTF-8
mysql>show variables like "char%";
修改字符集
vim /etc/my.cnf
在[mysqld] 下面一行输入下面两行配置 然后按:wq
character-set-server=utf8
collation-server=utf8_general_ci
再次查看字符编码
安装完成
End~