暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Centos7离线环境安装MySql8

云自由 2022-07-05
1045


  1. https://dev.mysql.com/downloads/mysql/下载mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar

  2. 建立目录

    [root@vm home]# mkdir mysql
    复制


  3. 上传tar文件到mysql目录

  4. 检查原有的mariadb并删除

    [root@vm home]# rpm -qa|grep mariadb
    mariadb-libs-5.5.52-1.el7.x86_64
    [root@vm home]# rpm -e --nodeps mariadb-libs
    复制

5.解压缩安装包

[root@vm mysql]# tar -xvf mysql-8.0.29-1.el7.x86_64.rpm-bundle.tar 
mysql-community-client-8.0.29-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.29-1.el7.x86_64.rpm
mysql-community-common-8.0.29-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.29-1.el7.x86_64.rpm
mysql-community-devel-8.0.29-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.29-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.29-1.el7.x86_64.rpm
mysql-community-libs-8.0.29-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.29-1.el7.x86_64.rpm
mysql-community-server-8.0.29-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.29-1.el7.x86_64.rpm
mysql-community-test-8.0.29-1.el7.x86_64.rpm
复制

6.依次安装rpm

[root@vm mysql]# rpm -ivh mysql-community-common-8.0.29-1.el7.x86_64.rpm 

[root@vm mysql]# rpm -ivh mysql-community-client-plugins-8.0.29-1.el7.x86_64.rpm

[root@vm mysql]# rpm -ivh mysql-community-libs-8.0.29-1.el7.x86_64.rpm

[root@vm mysql]# rpm -ivh mysql-community-client-8.0.29-1.el7.x86_64.rpm

[root@vm mysql]# rpm -ivh mysql-community-icu-data-files-8.0.29-1.el7.x86_64.rpm

[root@vm mysql]# rpm -ivh mysql-community-server-8.0.29-1.el7.x86_64.rpm
复制

7.停止mysql服务

[root@vm mysql]# systemctl stop mysqld
[root@vm mysql]# systemctl status mysqld
复制

8.初始化mysql

[root@vm mysql]# mysqld --initialize --console
复制

9.目录授权

[root@vm lib]# chown -R mysql:mysql var/lib/mysql/
复制

10.查看mysql临时密码,此处临时密码是31rSi;4wgt(h

[root@vm lib]# cat var/log/mysqld.log
2022-06-30T06:13:31.333655Z 0 [System] [MY-013169] [Server] usr/sbin/mysqld (mysqld 8.0.29) initializing of server in progress as process 73142
2022-06-30T06:13:31.354233Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-06-30T06:13:59.524843Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-06-30T06:14:48.614092Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 31rSi;4wgt(h
复制

11.启动mysql服务

[root@vm lib]# systemctl start mysqld
复制

12.使用临时密码登录mysql

[root@vm lib]# mysql -u root -p
Enter password:
复制

13.修改当前登录用户密码

mysql> alter user user() identified by 'Abcd@1234';
可以使用alter USER 'root'@'localhost' IDENTIFIED BY 'Abcd@1234';
密码不能少于8位,过于简单。
复制

14.新建数据库

mysql> create database sunxiaowen;
复制

15.新建用户,授权访问

--创建用户,可以从任意远程主机登陆,使用通配符%
mysql> create user 'sunxiaowen'@'%' identified by '123456';
--显示所有用户
mysql> select user,host from mysql.user;
+------------------+-----------+
| user             | host     |
+------------------+-----------+
| sunxiaowen       | %         |
| mysql.infoschema | localhost |
| mysql.session   | localhost |
| mysql.sys       | localhost |
| root             | localhost |
+------------------+-----------+

--将数据库sunxiaowen上的所有权限all privileges授予用户'sunxiaowen'@'%'
mysql> GRANT ALL PRIVILEGES ON sunxiaowen.* TO 'sunxiaowen'@'%';
复制

16.安装后配置文件默认在/etc/my.cnf,默认配置如下:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
复制

17.修改mysql数据目录

--新建目录
[root@vm mysql]# cd home
[root@vm home]# mkdir data

--停止mysql服务进程
[root@vm home]# mysqladmin -u root -p shutdown

--移动原数据目录到新目录
[root@vm home]# mv var/lib/mysql home/data

--编辑my.cnf配置文件
[root@vm mysql]# vim etc/my.cnf
datadir=/home/data/mysql
socket=/home/data/mysql/mysql.sock

--创建连接文件
[root@vm mysql]# ln -s /home/data/mysql/mysql.sock /var/lib/mysql/mysql.sock

--启动mysql服务
[root@vm mysql]# systemctl start mysqld
复制


文章转载自云自由,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论