赞
踩
我这里在home目录下创建了一个MySQL目录
将文件上传到/home/MySQL
cd /home/MySQL
tar -xvf mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
rpm -qa | grep -i mysql
rpm -qa | grep -i mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
删除残留文件 [ 必须删除,否则启动不了MySQL ]
rm -rf /var/lib/mysql
/var/log/mysqld.log
yum install libaio
yum install perl
yum install net-tools
rpm -ivh mysql-community-common-5.7.44-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.44-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.44-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.44-1.el7.x86_64.rpm
我下载的tar包没有libs和server,就单独下载了一个
rpm -qa|grep -i mysql
mysqladmin --version
参数 | 路径 | 解释 | 备注 |
---|---|---|---|
–basedir | /usr/bin | 相关命令目录 | mysqladmin mysqldump等命令 |
–datadir | /var/lib/mysql/ | mysql数据库文件的存放路径 | |
–plugin-dir | /usr/lib64/mysql/plugin | mysql插件存放路径 | |
–log-error | /var/log/mysqld.log | mysql错误日志路径 | |
–pid-file | /var/run/mysqld/mysqld.pid | 进程pid文件 | |
–socket | /var/lib/mysql/mysql.sock | 本地连接时用的unix套接字文件 | |
/usr/share/mysql | 配置文件目录 | mysql脚本及配置文件 | |
/etc/my.cnf | mysql配置文件 | cat /etc/my.cnf |
/etc/systemd/system/multi-user.target.wants/mysqld.service
#启动
systemctl start mysqld
#关闭
systemctl stop mysqld
#重启
systemctl restart mysqld
#查看状态
systemctl status mysqld
#查看服务是否自动启动(是:enabled | 否:disabled)
systemctl list-unit-files|grep mysqld.service
#设置开机启动:如不是enabled可以运行如下命令设置自启动
systemctl enable mysqld
#重新加载服务配置
systemctl daemon-reload
#如果希望不进行自启动,运行如下命令设置
systemctl disable mysqld
ps -ef | grep -i mysql
mysql 安装完成之后,在 /var/log/mysqld.log 文件中给 root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql。
grep password /var/log/mysqld.log
mysql -h localhost -P 3306 -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
#–或者
SET password FOR 'root'@'localhost'= password('123456');
注意: mysql5.7 默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误
#如果不需要密码策略,在/etc/my.cnf 文件中的最后添加如下配置禁用即可
validate_password = off
#重新启动mysql服务使配置生效
systemctl restart mysqld
SHOW VARIABLES LIKE 'character%';
[client]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4
#重启服务器
systemctl restart mysqld
# 查看
SHOW VARIABLES LIKE 'character%';
--修改已创建数据库的字符集
ALTER DATABASE 数据库名 CHARACTER SET 'utf8mb4';
--修改已创建数据表的字符集
ALTER TABLE 表名 CONVERT TO CHARACTER SET 'utf8mb4';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
#查看host
select host from user where user='root';
#修改host
update user set host = '%' where user ='root';
#刷一下配置
FLUSH PRIVILEGES;
#重启服务器
systemctl restart mysqld
#查看防火墙状态
firewall-cmd --state
#关闭防火墙
systemctl stop firewalld.service
#禁用开机启动
systemctl disable firewalld.service
#查看防火墙状态
firewall-cmd --state
#开启防火墙
systemctl start firewalld.service
#设置开机自启
systemctl enable firewalld.service
#设置开放的端口号
firewall-cmd --zone=public --add-port=3306/tcp --permanent
#重启防火墙
firewall-cmd --reload
#查看开放的端口
firewall-cmd --list-ports
CREATE USER Lance IDENTIFIED BY '123456';
--mysql5.5
mysql> UPDATE mysql.user SET password = PASSWORD('1234') WHERE user = 'Lance';
--mysql5.7
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('1234') WHERE user = 'Lance';
--必须用该命令才能生效。否则,需重启服务。
mysql> FLUSH PRIVILEGES;
UPDATE mysql.user SET user = '蓝山' WHERE user = 'Lance';
FLUSH PRIVILEGES;
DROP user '蓝山';
FLUSH PRIVILEGES;
#写法
GRANT 权限1, 权限2, …权限n ON 数据库名称.表名称 TO '用户名'@'用户地址' IDENTIFIED BY '连接口令';
#给用户授 增删查改 的权限
GRANT SELECT, INSERT, DELETE, UPDATE ON db_test.* TO 'Lance'@'%';
FLUSH PRIVILEGES;
SHOW GRANTS;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。