mysql5.7版本二进制包安装方法

官网下载地址https://dev.mysql.com/downloads/mysql/5.7.html#downloads

系统环境CentOS6.8

一、添加mysql用户组及mysql用户

# groupadd mysql

# useradd -M -s /sbin/nologin mysql -g mysql

二、将二进制文件解压到指定的安装目录:/usr/local/mysql

# tar zxf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz  

 # mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql

三、创建mysql数据存放的目录:/data/mysql

# mkdir -p /data/mysql 

四、更改所属的组和用户

# chown -R mysql:mysql /usr/local/mysql/

# chown -R mysql:mysql /data/mysql/

五、编辑参数文件

# vim /etc/my.cnf 

[client]
port = 3306
socket = /data/mysql/mysql.sock

[mysqld]
port = 3306
user = mysql
socket = /data/mysql/mysql.sock

basedir = /usr/local/mysql
datadir = /data/mysql
 

#以下设置utf8mb4字符集,可忽略
character-set-server = utf8mb4 
init_connect='SET NAMES utf8mb4'
default_storage_engine = innodb

#日志记录路径,需要mysql账户对其有写权限,先touch新建再更改所属组

log-error=/var/log/mysqld.log

六、初始化数据库

# cd /usr/local/mysql/

# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

2018-11-23T02:45:44.003058Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-23T02:45:44.670512Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-23T02:45:44.837045Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-23T02:45:44.941312Z 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: e00a5bb2-eec9-11e8-8e2a-000c29e7dca1.
2018-11-23T02:45:44.950510Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-23T02:45:44.952934Z 1 [Note] A temporary password is generated for root@localhost: w>;_EkWdw7SJ

[Note]部分为自动生成的password 

如果报错:./bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

执行以下命令:

# yum -y install libaio

七、配置启动文件

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

# chmod 755 /etc/init.d/mysqld

# chkconfig --add mysqld 

# chkconfig --list mysqld

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

八、启动mysql服务

# service mysqld start

注:在/etc/profile中加入以下环境变量,可以用mysql代替/usr/local/mysql/bin/mysql启动

MYSQL_HOME=/usr/local/mysql 

export PATH=$PATH:$MYSQL_HOME/bin

设置后需要重新加载一下:

# source /etc/profile

九、初始化密码

#mysql -uroot -p‘xxxxx‘ #登陆MySQL客户端,密码为之前随机生成
mysql> SET PASSWORD=PASSWORD('root'); 
mysql> flush privileges;

想让root在其他客户端也能管理数据库:

执行 : GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' ; 

然后 执行:flush privileges; 
 

十、安全配置

# mysql_secure_installation 

详情点击查看严格的密码要求

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值