CentOS7.4 mysql安装

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

'''

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,311评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,339评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,671评论 0 342
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,252评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,253评论 5 371
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,031评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,340评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,973评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,466评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,937评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,039评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,701评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,254评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,259评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,485评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,497评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,786评论 2 345

推荐阅读更多精彩内容