Linux部署MySQL5.7.17
mkdir /opt/mysql
cd /opt/mysql
#mysql下载官网:
#https://downloads.mysql.com/archives/community/
#下载server、client、lib和common
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-5.7.17-1.el7.x86_64.rpmwget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-5.7.17-1.el7.x86_64.rpmwget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-5.7.17-1.el7.x86_64.rpmwget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-5.7.17-1.el7.x86_64.rpm
#MySQL安装环境准备
#卸载mariadb-libs
rpm -e mariadb-libs --nodeps
#安装依赖
yum install libaio -y
yum install net-tools -y
#安装下载后的4个安装包
rpm mysql-community* -ivh
#安装后查询MySQL版本
mysqladmin --version
#启动MySQL
systemctl start mysqld
mysql的登录
1、查看临时密码
2、登陆root帐号
3、修改root密码
#查看mysql初始密码
grep 'temporary password' /var/log/mysqld.log
#登录mysql
mysql -uroot -p
#输入密码
第一次使用需要更改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@123';
修改一下策略
查看
show variables like 'validate_password%';
set global validate_password_policy=0; # 关闭密码复杂性策略(LOW)
set global validate_password_length=3;
创建用户并授权
CREATE USER 'namida'@'%' IDENTIFIED BY 'Shiina@123';
GRANT ALL PRIVILEGES ON *.* TO 'namida'@'%';
flush privileges;
select * from mysql.user;
systemctl stop firewalld
4、创建数据库 数据库名自拟
CREATE DATABASE xcz;
5、创建表 表名、字段自拟,向表里添加几条数据
6、创建一个可远程操作的用户
CREATE USER 'namida2'@'192.168.1.109' IDENTIFIED BY 'Shiina@456';
7、给远程用户授予可操作步骤4创建的数据库内所有表的权限
GRANT ALL PRIVILEGES ON xcz.* TO 'namida2'@'192.168.1.109';
8、开放3306端口号
systemctl stop firewalld
9、windows下通过工具远程连接linux的数据库
MySQL密码找回
1、修改mysql配置文件 /etc/my.cnf 在[mysqld]下面添加skip-grant-tables
vim /etc/my.cnf
2、重启mysqld服务
systemctl restart mysqld
3、登陆mysql,此时不需要输入密码,直接回车即可
4、修改user表内的密码字段的值,该值需要使用password()函数加密
update mysql.user
set authentication_string=password('ABCabc123!')
where user='root' and host='localhost';
5、退出mysql使用新密码登陆
quitmysql -uroot -p