MySql教程

MySQL安装

本文主要是介绍MySQL安装,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

2.1.1 安装包准备

1)卸载自带的Mysql-libs(如果之前安装过mysql,要全都卸载掉)

[atguigu@hadoop102 software]$ rpm -qa | grep -i -E mysql\|mariadb | xargs -n1 sudo rpm -e --nodeps

2)将安装包和JDBC驱动上传到/opt/software,共计6个

01_mysql-community-common-5.7.16-1.el7.x86_64.rpm

02_mysql-community-libs-5.7.16-1.el7.x86_64.rpm

03_mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm

04_mysql-community-client-5.7.16-1.el7.x86_64.rpm

05_mysql-community-server-5.7.16-1.el7.x86_64.rpm

mysql-connector-java-5.1.27-bin.jar

2.1.2 安装MySQL

1)安装mysql依赖

[atguigu@hadoop102 software]$ sudo rpm -ivh 01_mysql-community-common-5.7.16-1.el7.x86_64.rpm

[atguigu@hadoop102 software]$ sudo rpm -ivh 02_mysql-community-libs-5.7.16-1.el7.x86_64.rpm

[atguigu@hadoop102 software]$ sudo rpm -ivh 03_mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm

2)安装mysql-client

[atguigu@hadoop102 software]$ sudo rpm -ivh 04_mysql-community-client-5.7.16-1.el7.x86_64.rpm

3)安装mysql-server

[atguigu@hadoop102 software]$ sudo rpm -ivh 05_mysql-community-server-5.7.16-1.el7.x86_64.rpm

4)启动mysql

[atguigu@hadoop102 software]$ sudo systemctl start mysqld

5)查看mysql密码

[atguigu@hadoop102 software]$ sudo cat /var/log/mysqld.log | grep password

2.1.3 配置MySQL

配置只要是root用户+密码,在任何主机上都能登录MySQL数据库。

1)用刚刚查到的密码进入mysql(如果报错,给密码加单引号)

[atguigu@hadoop102 software]$ mysql -uroot -p 'password'

2)设置复杂密码(由于mysql密码策略,此密码必须足够复杂)

mysql> set password=password("Qs23=zs32");

3)更改mysql密码策略

mysql> set global validate_password_length=4;

mysql> set global validate_password_policy=0;

4)设置简单好记的密码

mysql> set password=password("000000");

5)进入msyql库

mysql> use mysql

6)查询user表

mysql> select user, host from user;

7)修改user表,把Host表内容修改为%

mysql> update user set host="%" where user="root";

8)刷新

mysql> flush privileges;

9退出

mysql> quit;

这篇关于MySQL安装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!