今天水一篇mysql的安装教程
start
mysql文件下载(linux版), 不要积分
链接:https://pan.baidu.com/s/1c3cLHz6 密码:ic2m
一 .MySQL的数据库
1 .解压mysql文件
[root@wpixel04 www]# tar -xvf mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
#解压出的文件
[root@wpixel04 www]# ll
total 13
-rw-r--r--. 1 root root 592865280 Sep 17 22:10 mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415 25085192 Jun 24 2017 mysql-community-client-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 278292 Jun 24 2017 mysql-community-common-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 3778852 Jun 24 2017 mysql-community-devel-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 46236988 Jun 24 2017 mysql-community-embedded-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 24077820 Jun 24 2017 mysql-community-embedded-compat-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 128296360 Jun 24 2017 mysql-community-embedded-devel-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2238032 Jun 24 2017 mysql-community-libs-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2115696 Jun 24 2017 mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 55456196 Jun 24 2017 mysql-community-minimal-debuginfo-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 171537176 Jun 24 2017 mysql-community-server-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 15258732 Jun 24 2017 mysql-community-server-minimal-5.7.19-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 118490200 Jun 24 2017 mysql-community-test-5.7.19-1.el7.x86_64.rpm
2 .删除系统上已安装的MySql
[root@wpixel04 www]# yum remove mysql-libs
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be erased
--> 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
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================
Package Arch Version Repository Size
==============================================================================================================
Removing:
mariadb-libs x86_64 1:5.5.52-1.el7 @anaconda 4.4 M
Removing for dependencies:
postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M
Transaction Summary
==============================================================================================================
Remove 1 Package (+1 Dependent package)
Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : 2:postfix-2.10.1-6.el7.x86_64 1/2
Erasing : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/2
Verifying : 2:postfix-2.10.1-6.el7.x86_64 1/2
Verifying : 1:mariadb-libs-5.5.52-1.el7.x86_64 2/2
Removed:
mariadb-libs.x86_64 1:5.5.52-1.el7
Dependency Removed:
postfix.x86_64 2:2.10.1-6.el7
Complete!
3 .
[root@wpixel04 www]# rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm
[root@wpixel04 www]# rpm -ivh mysql-community-libs-5.7.19-1.el7.x86_64.rpm
[root@wpixel04 www]# rpm -ivh mysql-community-client-5.7.19-1.el7.x86_64.rpm
[root@wpixel04 www]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm --nodeps --force
[root@wpixel04 www]# rpm -ivh mysql-community-devel-5.7.19-1.el7.x86_64.rpm (可选)
4 .启动MySql
[root@wpixel04 www]# service mysqld start
或者
[root@wpixel04 www]# systemctl start mysqld.service
5 .查看root用户密码
[root@wpixel04 www]# cat /var/log/mysqld.log | grep password
2018-01-30T06:58:32.331349Z 1 [Note] A temporary password is generated for root@localhost: -:amHRLyQ5p(
# 密码: “-:amHRLyQ5p(“
6 .使用root用户登陆
[root@wpixel04 www]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.19
Copyright (c) 2000, 2017, 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>
7 .修改登陆密码
#这里密码要求必须含有数字,小写或大写字母,特殊字符
#密码规格不符合报错
mysql> alter user 'root'@'localhost' identified by 'wpixel';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
#密码设置成功
mysql> alter user 'root'@'localhost' identified by 'Wpixel_01';
Query OK, 0 rows affected (0.00 sec)
8 .mysql数据库操作
# 1.显示所有数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
# 2.创建数据库hive
mysql> create database hive;
Query OK, 1 row affected (0.00 sec)
# 3.创建一个允许外网IP访问的用户
mysql> create user 'wpixel'@'%' identified by 'Wpixel_01';
Query OK, 0 rows affected (0.00 sec)
# 4.给该用户授权
mysql> grant all on hive.* to 'wpixel'@'%';
Query OK, 0 rows affected (0.00 sec)
9 .用刚创建的用户远程登陆数据库
10 .总结
提示:数据库是有回收站的,所以不小心删除了,可以用flashback(闪回)的方式恢复数据库……(╯‵□′)╯︵┻━┻