1. 首先进入本机的源文件目录
'cd /usr/local/src'
2. 使用wget下载官方yum源的rpm包
'wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm'
3. 安装rpm包
'rpm -ivh mysql57-community-release-el7-8.noarch.rpm'
4. 再次使用yum来安装MySQL-server
'yum install -y mysql-server'
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid
5. 配置' my.cnf ' ' vim/ect/my.cnf '
'''
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server_id = 1
expire_logs_days = 3
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
// 配置文件加了两行代码,不知道意思
server_id = 1
expire_logs_days = 3
'''
6. 启动MySQL服务
' service mysqld restart '
查看是否启动成功
' ps aux|grep mysqld '
设置开机自启动
' systemctl enable mysqld '
7. 查看本机随机生成的密码
' grep "password" /var/log/mysqld.log '
8. 输入 ' mysql -u root -p ' 输入密码进入,第一次登陆需要充值完密码,要不什么也不能操作
9. 修改密码
' alter user 'root'@'localhost' identified by 'possword'; '
10. 刷新权限
' flush privileges; '
11. 增加root用户指定可以任意IP登录,如果想限制只能让指定IP登录请把%替换成IP地址
' grant all on *.* to 'root001'@'%' identified by 'Root@@' with grant option; '
12. MySQL启动和关闭启动mysql服务
' systemctl start mysqld.service '
停止mysql服务
' systemctl stop mysqld.service '
重启mysql服务
' systemctl restart mysqld.service '
查看mysql服务当前状态
' systemctl status mysqld.service '
设置mysql服务开机自启动
' systemctl enable mysqld.service '
停止mysql服务开机自启动
'systemctl disable mysqld.service '
退出MySQL
' exit '
过程图
'''
进入本机的源文件目录
[root@izldsnrx3imo6iz ~]# cd /usr/local/src/
使用wget下载官方yum源的rpm包
[root@izldsnrx3imo6iz src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
--2018-03-23 13:28:12-- http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.10.6.195
Connecting to repo.mysql.com (repo.mysql.com)|23.10.6.195|: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-03-23 13:28:12 (159 MB/s) - ‘mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116]
安装rpm包
[root@izldsnrx3imo6iz src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
warning: mysql57-community-release-el7-8.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-8 ################################# [100%]
再次使用yum来安装MySQL-server
[root@izldsnrx3imo6iz src]# yum -y install mysql-server
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 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
updates | 3.4 kB 00:00:00
(1/10): epel/x86_64/group_gz | 266 kB 00:00:00
(2/10): base/7/x86_64/group_gz | 156 kB 00:00:00
(3/10): epel/x86_64/updateinfo | 905 kB 00:00:00
(4/10): extras/7/x86_64/primary_db | 181 kB 00:00:00
(5/10): epel/x86_64/primary_db | 6.3 MB 00:00:00
(6/10): mysql-connectors-community/x86_64/primary_db | 18 kB 00:00:00
(7/10): base/7/x86_64/primary_db | 5.7 MB 00:00:00
(8/10): updates/7/x86_64/primary_db | 6.9 MB 00:00:00
(9/10): mysql-tools-community/x86_64/primary_db | 39 kB 00:00:00
(10/10): mysql57-community/x86_64/primary_db | 134 kB 00:00:00
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.21-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.21-1.el7 for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-5.7.21-1.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mysql-community-client.x86_64 0:5.7.21-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.21-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.21-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> 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: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.21-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.21-1.el7 will be obsoleting
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Installing:
mysql-community-libs x86_64 5.7.21-1.el7 mysql57-community 2.1 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-libs-compat x86_64 5.7.21-1.el7 mysql57-community 2.0 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.7.21-1.el7 mysql57-community 164 M
Installing for dependencies:
libaio x86_64 0.3.109-13.el7 base 24 k
mysql-community-client x86_64 5.7.21-1.el7 mysql57-community 24 M
mysql-community-common x86_64 5.7.21-1.el7 mysql57-community 272 k
Transaction Summary
========================================================================================================
Install 3 Packages (+3 Dependent packages)
Total download size: 192 M
Downloading packages:
(1/6): libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.21-1.el7.x86_64.rpm is not installed
(2/6): mysql-community-common-5.7.21-1.el7.x86_64.rpm | 272 kB 00:00:00
(3/6): mysql-community-libs-5.7.21-1.el7.x86_64.rpm | 2.1 MB 00:00:00
(4/6): mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm | 2.0 MB 00:00:00
(5/6): mysql-community-client-5.7.21-1.el7.x86_64.rpm | 24 MB 00:00:03
(6/6): mysql-community-server-5.7.21-1.el7.x86_64.rpm | 164 MB 00:00:23
--------------------------------------------------------------------------------------------------------
Total 7.8 MB/s | 192 MB 00:00:24
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-8.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.
Installing : mysql-community-common-5.7.21-1.el7.x86_64 1/7
Installing : mysql-community-libs-5.7.21-1.el7.x86_64 2/7
Installing : mysql-community-client-5.7.21-1.el7.x86_64 3/7
Installing : libaio-0.3.109-13.el7.x86_64 4/7
Installing : mysql-community-server-5.7.21-1.el7.x86_64 5/7
Installing : mysql-community-libs-compat-5.7.21-1.el7.x86_64 6/7
Erasing : 1:mariadb-libs-5.5.56-2.el7.x86_64 7/7
Verifying : mysql-community-client-5.7.21-1.el7.x86_64 1/7
Verifying : mysql-community-libs-compat-5.7.21-1.el7.x86_64 2/7
Verifying : mysql-community-libs-5.7.21-1.el7.x86_64 3/7
Verifying : mysql-community-server-5.7.21-1.el7.x86_64 4/7
Verifying : libaio-0.3.109-13.el7.x86_64 5/7
Verifying : mysql-community-common-5.7.21-1.el7.x86_64 6/7
Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 7/7
Installed:
mysql-community-libs.x86_64 0:5.7.21-1.el7 mysql-community-libs-compat.x86_64 0:5.7.21-1.el7
mysql-community-server.x86_64 0:5.7.21-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:5.7.21-1.el7
mysql-community-common.x86_64 0:5.7.21-1.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
配置my.cnf
[root@izldsnrx3imo6iz src]# vim /etc/my.cnf
启动MySQL服务
[root@izldsnrx3imo6iz src]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
查看本机随机生成的密码
[root@izldsnrx3imo6iz src]# grep "password" /var/log/mysqld.log
2018-03-23T05:33:45.893170Z 1 [Note] A temporary password is generated for root@localhost: z2&TnMgScqFv
输入 mysql -u root -p 输入密码进入
[root@izldsnrx3imo6iz src]# mysql -u root -p
输入密码
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21
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> alter user 'root'@'localhost' identified by 'Wangrui511!!';
Query OK, 0 rows affected (0.00 sec)
语法错误
mysql> flush privileges
-> flush privileges;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'flush privileges' at line 2
刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to 'root001'@'%' identified by 'Root@@' Wangrui!!;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Wangrui!!' at line 1
mysql> grant all on *.* to 'root001'@'%' identified by 'Root@@' Wangrui511!!;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Wangrui511!!' at line 1
mysql> grant all on *.* to 'root001'@'%' identified by 'Root@@' with grant option;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
增加root用户指定可以任意IP登录,如果想限制只能让指定IP登录请把%替换成IP地址
mysql> grant all on *.* to 'root001'@'%' identified by 'Wangrui511!!' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
刷新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
退出数据库
mysql> exit
Bye
数据库启动
[root@izldsnrx3imo6iz src]# systemctl start mysqld
[root@izldsnrx3imo6iz src]# systemctl enable mysqld
查看是否启动成功
[root@izldsnrx3imo6iz src]# ps aux|grep mysqld
mysql 1326 0.0 18.1 1119672 184560 ? Sl 13:33 0:01 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 1437 0.0 0.0 112660 972 pts/0 R+ 14:20 0:00 grep --color=auto mysqld
'''