linux rpm 安装mysql

1、下载MySql的rpm包

#官方rpm安装地址 可以选择自己想要的版本
https://downloads.mysql.com/archives/community/


wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-server-5.7.26-1.el7.x86_64.rpm

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-client-5.7.26-1.el7.x86_64.rpm

 wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-common-5.7.26-1.el7.x86_64.rpm
 
 wget https://downloads.mysql.com/archives/get/p/23/file/mysql-community-libs-5.7.26-1.el7.x86_64.rpm
 
  ll
total 196768
-rw-r--r-- 1 root root  25381952 Apr 15  2019 mysql-community-client-5.7.26-1.el7.x86_64.rpm
-rw-r--r-- 1 root root    280904 Apr 15  2019 mysql-community-common-5.7.26-1.el7.x86_64.rpm
-rw-r--r-- 1 root root   2274268 Apr 15  2019 mysql-community-libs-5.7.26-1.el7.x86_64.rpm
-rw-r--r-- 1 root root 173541272 Apr 15  2019 mysql-community-server-5.7.26-1.el7.x86_64.rpm

2、检查是否依赖冲突

#在安装之前先检查一下是否有历史版本,包括可能产生冲突的mariadb软件包。
rpm -qa|grep mariadb
rpm -qa|grep mysql
rpm -qa|grep MySQL

mariadb-libs-5.5.60-1.el7_5.x86_64

#卸载
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

3、解压安装mysql

#安装依赖 如果不安装依赖启动服务会失败
#解决依赖缺失
yum -y install autoconf libaio

#注意安装顺序
rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm 

rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm 

rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm 

rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm  --force --nodeps

#卸载使用
rpm -e mysql-community-client-5.7.26-1.el7.x86_64 --nodeps
rpm -e mysql-community-common-5.7.26-1.el7.x86_64 --nodeps
rpm -e mysql-community-server-5.7.26-1.el7.x86_64 --nodeps
rpm -e mysql-community-libs-5.7.26-1.el7.x86_64 --nodeps
#检查包的安装情况
rpm -qa | grep mysql
mysql-community-client-5.7.26-1.el7.x86_64
mysql-community-libs-5.7.26-1.el7.x86_64
mysql-community-common-5.7.26-1.el7.x86_64
mysql-community-server-5.7.26-1.el7.x86_64

4、启动mysql

#检查安装版本
mysql --version
mysql  Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using  EditLine wrapper
#启动
systemctl start mysqld
ystemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-05-13 14:29:04 CST; 5s ago
     Docs: man:mysqld(8)

5、获取临时密码

grep 'temporary password' /var/log/mysqld.log
2022-05-13T06:29:01.002269Z 1 [Note] A temporary password is generated for root@localhost: phozV(oqZ46=

6、登录

#初始密码 不要写在-p后面 因为不识别()符号
mysql -uroot -p

7、配置密码策略

#修改validate_password_policy参数值为0(1为开启复杂策略)

mysql> set global validate_password_policy=0;

#修改validate_password_length参数值为1
mysql> set global validate_password_length=1;

8、设置连接密码

#修改密码
mysql> alter user 'root'@'localhost' identified by '密码';

#如果不授权直接用可视化工具连接会“连接失败”。
#授权root允许远程访问(可视化软件可以建立链接)
mysql> grant all privileges on *.* to 'root'@'%' identified by '密码'; 

#保存设置
mysql> flush privileges;

9、修改配置

 vim /etc/my.cnf
# my.cnf⽂件⽂件中的[mysqld]段添加
#表名大小写敏感开启关闭
lower_case_table_names=1
#mysql关闭ssl认证  表⽰跳过ssl认证
skip-ssl
#设置tmp大小
tmp_table_size= 128M
#设置连接睡眠连接超时秒数,如果某个连接超时,会被mysql自然终止。 
wait_timeout=1200

#开启慢查询日志
slow_query_log = ON
slow_query_log_file = /var/lib/mysql/tmp_slow.log     
long_query_time = 1

10、连接测试

#本地连接测试
mysql -uroot -p密码

#远程连接测试
mysql -h 127.0.0.1 -uroot -p密码

#查看
#表名大小写敏感是否关闭 1表示
show variables like '%lower_case_table_names%'; 
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_table_names | 1     |
+------------------------+-------+


#查看ssl认证是否关闭 0关闭
show session status like "Ssl%";
+--------------------------------+-------+
| Variable_name                  | Value |
+--------------------------------+-------+
| Ssl_accept_renegotiates        | 0     |
| Ssl_accepts                    | 0     |
| Ssl_callback_cache_hits        | 0     |
| Ssl_cipher                     |       |
| Ssl_cipher_list                |       |
| Ssl_client_connects            | 0     |
| Ssl_connect_renegotiates       | 0     |
| Ssl_ctx_verify_depth           | 0     |
| Ssl_ctx_verify_mode            | 0     |
| Ssl_default_timeout            | 0     |
| Ssl_finished_accepts           | 0     |
| Ssl_finished_connects          | 0     |
| Ssl_server_not_after           |       |
| Ssl_server_not_before          |       |
| Ssl_session_cache_hits         | 0     |
| Ssl_session_cache_misses       | 0     |
| Ssl_session_cache_mode         | NONE  |
| Ssl_session_cache_overflows    | 0     |
| Ssl_session_cache_size         | 0     |
| Ssl_session_cache_timeouts     | 0     |
| Ssl_sessions_reused            | 0     |
| Ssl_used_session_cache_entries | 0     |
| Ssl_verify_depth               | 0     |
| Ssl_verify_mode                | 0     |
| Ssl_version                    |       |
+--------------------------------+-------+

#查看tmp大小
show variables like '%tmp%';

#查看连接超时时间
 show global variables like 'wait_timeout'; 

11、创建用户

-- 创建账户,"%"是无登录限制的,“123”是密码
create user 'liwker'@'%' identified by '123';
 
-- "localhost"是限制为本地登录
create user 'liwker'@'localhost' identified by '123';
 
-- 这个是限制 ip 为 10.11.20.30 的主机访问
create user 'liwker'@'10.11.20.30' identified by '123';

12、配置权限

-- Liwker库的student表的 只读权限 分配给 liwker 账户
grant select on Liwker.student to liwker@'%';
 
-- Liwker库(所有表)的 多个权限 分配给 liwker 账户
grant select,insert,delete,update on Liwker.* to liwker@'%';
 
-- Liwker库的 所有权限 分配给 liwker 账户
grant all on Liwker.* to liwker@'%';
 
-- 所有库的 多个权限 分配给 mascash
grant select,insert,update on *.* to mascash@'%';

-- 所有库的 所有权限 分配给 liwker 账户
grant all on *.* to liwker@'%';

 
-- 刷新权限
flush privileges;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值