linux 下部署 mysql5.7.28

linux下安装 mysql-5.7.28

mysql官网:

5.6.12的版本包

http://cdn.mysql.com//archives/mysql-5.6/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz

下载一个安装包【所有版本】

https://downloads.mysql.com/archives/community/

准备工作

  • 1.下载编译工具

 yum install -y ncurses-devel libaio-devel cmake gcc gcc-c++ glibc  rpm-build  autoconf
  • 2.下载mysql5.7.28版本包【我是提前下载好,拖进linux服务器的】

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

2.卸载自带的mariadb
[forest@ss-test data]$ rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[forest@ss-test data]$ rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

  • 3.创建数据库用户

useradd mysql -s /sbin/nologin -M 

1.将mysql5.7.28包放入data 目录

2.解压:

tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz     

3.改名:

mv mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz  /data/mysql.5.7.28

4.软连接:

ln -s /data/mysql.5.7.28/ /data/mysql

5.进入到mysql解压目录support

cd /data/mysql/support-files/   
1.创建一个my_default.cnf文件:(mysql5.6版本有此文件)

vim my_default.cnf 配置内容如下

​ 配置仅供参考!!!!!!!!!!!!!!

[mysqld]
server_id=2
log-bin = /data/mysql/logs/mysql-bin.log
#设置mysql的安装目录
basedir =/data/mysql/
#设置mysql数据库的数据存放目录
datadir = /data/mysql/data
#设置端口
port = 3306
socket = /tmp/mysql.sock
#设置字符集
character-set-server=utf8
#日志存放目录
log-error = /data/mysql/logs/mysqld.log
pid-file = /data/mysql/data/mysqld.pid
###### 2.查看

[root@suzhu support-files]# ll

-rw-r--r--. 1 mysql mysql   773 9月  27 2019 magic
-rw-r--r--. 1 mysql mysql   703 6月  10 13:17 my_default.cnf    #就是这个
-rwxr-xr-x. 1 mysql mysql  1061 9月  27 2019 mysqld_multi.server
-rwxr-xr-x. 1 mysql mysql   894 9月  27 2019 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 10576 9月  27 2019 mysql.server

6.创建好后,复制出一个my.cnf到/etc/下面

cp /data/mysql/support-files/my_default.cnf  /etc/my.cnf

创建日志目录,授权.

mkdir /data/mysql/logs/
#授权
chown -R mysql.mysql /data/mysql/

7.初始化

/data/mysql/bin/mysqld  --initialize --user=mysql --basedir=/data/mysql/ --datadir=/data/mysql/data/

1.初始化后会生成一个log文件,里面有数据库root用户的密码如下

[root@suzhu support-files]# cat /data/mysql/logs/mysqld.log   

2020-06-10T05:34:13.737288Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2020-06-10T05:34:14.871771Z 0 [Warning] InnoDB: New log files created, LSN=45790

2020-06-10T05:34:14.995237Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2020-06-10T05:34:15.060539Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0588e10d-aadc-11ea-b830-000c29eb148e.

2020-06-10T05:34:15.061382Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2020-06-10T05:34:15.537510Z 0 [Warning] CA certificate ca.pem is self signed.

2020-06-10T05:34:15.636684Z 1 [Note] A temporary password is generated for root@localhost: FO>pw!nQU7-s

8.复制启动脚本到初始化目录

cp /data/mysql/support-files/mysql.server  /etc/init.d/mysqld 

9.替换启动脚本中的路径

sed -i "s#usr/local#data#g" /etc/init.d/mysqld /data/mysql/bin/mysqld_safe 

10.设置成systemctl启动

配置如下

vim /usr/lib/systemd/system/mysqld.service 
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

11.配置环境变量

echo 'PATH=/data/mysql/bin/:$PATH' >/etc/profile.d/mysql.sh

12.加载环境变量

 source /etc/profile.d/mysql.sh

13.给启动脚本授权700

 chmod 700 /etc/init.d/mysqld         

14.启动

systemctl start mysqld

15.进入mysql并更改密码

/data/mysql/bin/mysql -u root -p FO>pw!nQU7-s

16.更改密码

mysql> set password=password('qazwsx123456')   
mysql> flush privileges;

完结

拓展img

centos6系统的开机自启

[root@db02 mysql-5.6.36]# chkconfig mysqld on

centos7系统的开机自启

[root@db02 mysql-5.6.36]# systemctl enable mysqld

#MySQL登陆
[root@db02 ~]# mysql -uuser -ppassword -Ssocket -hhost
#MySQL基本操作及基本优化
#查看库
mysql> show databases;

#删库
mysql> drop database test;

#使用库
mysql> use mysql

#查看表
mysql> show tables;

#查看当前所在库
mysql> select database();

#查看mysql用户
mysql> select user,host from user;
mysql> select user,host,password from user;

#删除用户
mysql> select user,host from user;
mysql> drop user ''@'db';
mysql> drop user root@db;
mysql> drop user root@'::1';
mysql> drop user root@'127.0.0.1';

2.授权forest普通用户
grant all privileges on *.* to 'forest'@'localhost' identified by 'forest';
 grant all privileges on *.* to 'forest'@'192.168.0.4' identified by 'forest';
 修改用户的登陆ip
 rename user 'forest'@'localhost' to 'forest'@'192.168.0.4';
删除用户
drop user lzl@'%';
https://www.cnblogs.com/lemon-flm/p/7597879.html
posted @ 2020-06-12 15:53  名字长的像一只老山羊  阅读(53)  评论(0编辑  收藏  举报