Linux-CentOS6.9安装MySQL-5.7.22

13 篇文章 0 订阅
3 篇文章 0 订阅

#Linux-CentOS6.9安装MySQL-5.7.22

创建mysql用户组和用户

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql   # 使用-r参数表示mysql用户是一个系统用户 不能登录 /usr/sbin/useradd -r -g mysql mysql

安装mysql依赖

yum install libaio

下载mysql

cd /data0/software
wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

或手动下载

进入
https://dev.mysql.com/downloads/mysql/

进入
https://dev.mysql.com/downloads/mysql/5.7.html#downloads

选择 Linux - Generic

Linux - Generic (glibc 2.12) (x86, 64-bit), Compressed TAR Archive

下载
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

解压到安装目录 /usr/local

tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local

重命名

cd /usr/local
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql-5.7.22

mysql权限

chmod +w /usr/local/mysql-5.7.22
chown -R mysql:mysql /usr/local/mysql-5.7.22

到此mysql安装完毕;接下来我们创建一个mysql实例

创建mysql数据库存放目录

mkdir -p /data0/mysql/3306/data/
mkdir -p /data0/mysql/3306/binlog/
mkdir -p /data0/mysql/3306/relaylog/
chown -R mysql:mysql /data0/mysql/

初始化数据库

在5.7.6版本以前使用 mysql_install_db

/usr/local/mysql-5.7.22/bin/mysql_install_db --basedir=/usr/local/mysql-5.7.22 --datadir=/data0/mysql/3306/data --user=mysql

mysql-5.7.22 使用 mysqld --initialize

/usr/local/mysql-5.7.22/bin/mysqld --user=mysql --basedir=/usr/local/mysql-5.7.22 --datadir=/data0/mysql/3306/data --initialize

显示信息如下;记录下最后一行 root@localhost: Oeh5jU%nrYpy mysql生成的root临时密码;Oeh5jU%nrYpy

2018-04-25T02:57:00.167836Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-25T02:57:02.059707Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-25T02:57:02.287762Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-25T02:57:02.379891Z 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: 544049f1-4834-11e8-b5c2-0800274cda33.
2018-04-25T02:57:02.382838Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2018-04-25T02:57:02.391178Z 1 [Note] A temporary password is generated for root@localhost: Oeh5jU%nrYpy

mysql配置

vi /etc/my3306.cnf

[mysqld]
basedir=/usr/local/mysql-5.7.22/
datadir=/data0/mysql/3306/data/
socket=/tmp/mysql3306.sock
user=mysql
port=3306

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# 允许向数据库插入空值
sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysqld_safe]
log-error=/tmp/mysqld3306.log
pid-file=/tmp/mysqld3306.pid

[client]
socket = /tmp/mysql3306.sock

启动mysql服务

/usr/local/mysql-5.7.22/bin/mysqld_safe --defaults-file=/etc/my3306.cnf &

查看是否启动成功

ps -ef |grep mysql

能看到类似下面的信息,说明启动成功;

/bin/sh /usr/local/mysql-5.7.22/bin/mysqld_safe --defaults-file=/etc/my3306.cnf
/usr/local/mysql-5.7.22/bin/mysqld --defaults-file=/etc/my3306.cnf --basedir=/usr/local/mysql-5.7.22/ --datadir=/data0/mysql/3306/data --plugin-dir=/usr/local/mysql-5.7.22//lib/plugin --user=mysql --log-error=/tmp/mysqld3306.log --pid-file=/tmp/mysqld3306.pid --socket=/tmp/mysql3306.sock

连接mysql

/usr/local/mysql-5.7.22/bin/mysql -uroot -pOeh5jU%nrYpy -P3306 -hlocalhost

如果连接不上加 -S参数

/usr/local/mysql-5.7.22/bin/mysql -uroot -pOeh5jU%nrYpy -S /tmp/mysql3306.sock

连上后,在做任何操作前,mysql要求要改掉root的临时密码后才能进行操作;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'xxxxxxx';

alter user 'root'@'localhost' identified by '123456';

接下来我们再创建一个mysql实例,与第一个实例步骤一样,换一下端口就可以了;

创建mysql数据库存放目录

mkdir -p /data0/mysql/3307/data/
mkdir -p /data0/mysql/3307/binlog/
mkdir -p /data0/mysql/3307/relaylog/
chown -R mysql:mysql /data0/mysql/

初始化mysql3307数据库,记录临时密码

/usr/local/mysql-5.7.22/bin/mysqld --user=mysql --basedir=/usr/local/mysql-5.7.22 --datadir=/data0/mysql/3307/data --initialize

2018-04-25T04:25:30.859338Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-25T04:25:32.789208Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-25T04:25:33.120661Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-25T04:25:33.188472Z 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: b1bd5dc3-4840-11e8-b8f8-0800274cda33.
2018-04-25T04:25:33.191384Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2018-04-25T04:25:33.195451Z 1 [Note] A temporary password is generated for root@localhost: phHPJKKOr0/_

mysql3307配置 与3306配置一样,把全部3306改为3307

vi /etc/my3307.cnf

启动mysql3307

/usr/local/mysql-5.7.22/bin/mysqld_safe --defaults-file=/etc/my3307.cnf &

连接mysql3307 并更改临时密码

/usr/local/mysql-5.7.22/bin/mysql -uroot -p'phHPJKKOr0/_' -P3307 -hlocalhost

mysql> alter user 'root'@'localhost' identified by '123456';

配置开机自动启动

vi /etc/rc.local

在末尾增加两行

/usr/local/mysql-5.7.22/bin/mysqld_safe --defaults-file=/etc/my3306.cnf &
/usr/local/mysql-5.7.22/bin/mysqld_safe --defaults-file=/etc/my3307.cnf &

一定要注意最后的 & 一定不能少 否则CentOS系统将启不来 会一直卡在进度条~~~!!!

创建快捷方式

ln -s /usr/local/mysql-5.7.22/bin/mysql /usr/bin/mysql

连接mysql不用输入全路径了

mysql -uroot -p123456

mysql -uroot -p123456 -P3307

新建mysql用户 并授权外部访问

mysql -uroot -p123456 -h127.0.0.1 -P3306
GRANT ALL PRIVILEGES ON *.* TO 'cuber'@'%' IDENTIFIED BY '12345678';
exit;

mysql -uroot -p123456 -h127.0.0.1 -P3307
GRANT ALL PRIVILEGES ON *.* TO 'cuber'@'%' IDENTIFIED BY '12345678';
exit;

修改防火墙配置,增加两行

vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3307 -j ACCEPT

重启防火墙

service iptables restart

外部可以直接使用cuber用户访问mysql数据库

mysql -ucuber -p12345678 -h100.100.100.100 -P3306

mysql -ucuber -p12345678 -h100.100.100.100 -P3307

参考网址

https://www.linuxidc.com/Linux/2016-04/130414.htm
https://www.cnblogs.com/kanyun/p/8075414.html
https://www.cnblogs.com/coderls/p/6848873.html
https://blog.csdn.net/sunggff/article/details/74611780

http://zyan.cc/nginx_php_v6/
http://zyan.cc/nginx_php_v7/

GRANT ALL PRIVILEGES ON . TO ‘admin’@‘localhost’ IDENTIFIED BY ‘123456’;
GRANT ALL PRIVILEGES ON . TO ‘admin’@‘127.0.0.1’ IDENTIFIED BY ‘123456’;

grant Replication client, replication slave, PROCESS on . to repl@‘10.10.%’ identified by ‘123456’;

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值