centos7 下安装mysql 服务详解
安装mysql
- 下载安装mysql 源
[root@miao ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
--2018-12-11 21:25:08-- http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 2.17.212.38
Connecting to repo.mysql.com (repo.mysql.com)|2.17.212.38|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6140 (6.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql-community-release-el7-5.noarch.rpm’
100%[=============================================================================================================================>] 6,140 2.18KB/s in 2.8s
2018-12-11 21:25:13 (2.18 KB/s) - ‘mysql-community-release-el7-5.noarch.rpm’ saved [6140/6140]
[root@miao ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-release-el7-5 ################################# [100%]
- 安装mysql
[root@miao ~]# yum install -y mysql-community-server
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 3.2 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
mysql56-community | 2.5 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/9): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/9): extras/7/x86_64/primary_db | 154 kB 00:00:00
(3/9): epel/x86_64/primary
......
......
......
Installed:
mysql-community-libs.x86_64 0:5.6.42-2.el7 mysql-community-server.x86_64 0:5.6.42-2.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:5.6.42-2.el7 mysql-community-common.x86_64 0:5.6.42-2.el7
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7
perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7
Replaced:
mariadb-libs.x86_64 1:5.5.52-1.el7
Complete!
启动,停止or 重启mysql
启动:systemctl start mysqld
停止:systemctl stop mysqld
重启:systemctl restart mysqld
修改初始化密码
- 进入mysql shell:(默认密码为空)
[root@miao ~]# 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.6.42 MySQL Community Server (GPL)
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>
注意:
我这个版本mysql 默认密码为空,有的版本则是系统生成随机密码,查看随机密码方法如下:
查看系统随机默认密码:(使用随机密码登录之后,系统随后会强制要求修改)
grep ‘temporary password’ /var/log/mysqld.log
- 修改密码
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
mysql> update user set password=password('newPass123') where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
添加远程连接用户
mysql> grant all privileges on *.* to 'user01'@'%' identified by 'newPass123';
Query OK, 0 rows affected (0.00 sec)
这句命令的意思:grant 表示授权,all privileges 表示所有权限,on . 表示所有库的所有表(当然可以指定某些库的某些表),to ‘user01’@’%’ 表示授权给用户名为user01,ip无限制的用户,by ‘newPass123’ 表示user01 的密码。
之后服务器关闭浏览器或者开启3306端口后,就可以远程连接此mysql服务。