CentOS Linux release 7.2.1511安装MySql5.7.16

前端之家收集整理的这篇文章主要介绍了CentOS Linux release 7.2.1511安装MySql5.7.16前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本机版本:



安装MysqL5.7.16:

1、火狐浏览器访问官网http://dev.MysqL.com/downloads/MysqL/,点击downloads然后点击MysqL Community Server,切换Linux- generic



2、点击download按钮跳转按钮,按F12,点击网络,然后点击No thanks,just start my download,在网络那里查看请求的url



3、复制请求的url,在服务器上输入

wget http://dev.MysqL.com/get/Downloads/MysqL-5.7/MysqL-5.7.16-linux-glibc2.5-x86_64.tar.gz


4、查看文件与解压文件,输入:

tar -zxvf MysqL-5.7.16-linux-glibc2.5-x86_64.tar.gz
解压后输入:ll命令查看:


重命名与移动文件夹,输入:

mv MysqL-5.7.16-linux-glibc2.5-x86_64 /usr/local/MysqL

5、添加系统MysqL组和MysqL用户以及修改目录的权限:

groupadd MysqL
useradd -r -g MysqL MysqL

cd /usr/local

chown -R MysqL MysqL/
chgrp -R MysqL MysqL/

mkdir /usr/local/MysqL/data /usr/local/MysqL/log 


6、创建cnf文件
vim /etc/my.cnf
清除内容,复制粘贴以下内容,然后按esc输入:wq进行保存退出
[client]
port = 3306
socket = /tmp/MysqL.sock

[MysqLd]
server_id=10
port = 3306
user = MysqL
socket = /tmp/MysqL.sock
basedir = /usr/local/MysqL
datadir = /usr/local/MysqL/data
pid-file = /usr/local/MysqL/data/MysqL.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
#####====================================[innodb]==============================
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:1024M:autoextend

#####====================================[log]==============================
log_error = /usr/local/MysqL/log/MysqL-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /usr/local/MysqL/log/MysqL-slow.log

sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

7、安装数据库
cd MysqL/
bin/MysqLd --initialize --user=MysqL --basedir=/usr/local/MysqL --datadir=/usr/local/MysqL/data  --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp



8、配置启动文件与启动服务
cp support-files/MysqL.server /etc/init.d/MysqL
/etc/init.d/MysqLd restart



9、配置环境变量
vi /etc/profile 

添加行:MysqL_HOME=/usr/local/MysqL
PATH添加::$MysqL_HOME/bin
export添加MysqL_HOME

然后按esc输入:wq进行保存退出


10、进入MysqL修改密码
查看初始密码
cat /root/.MysqL_secret

登录
bin/MysqL -uroot -p
输入cat查看的密码

修改密码
update MysqL.user set authentication_string=password('root') where user='root';

SET PASSWORD=PASSWORD('root');

11、添加dba用户

use MysqL

GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY 'test' WITH GRANT OPTION;

flush privileges;


’12、添加数据库与分配用户权限

CREATE DATABASE `zp` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;


GRANT ALL ON zp.* TO zp@'%' IDENTIFIED BY '123456';


13、防火墙开放相关端口

firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --query-port=3306/tcp

如果query的命令执行结果为no,则把add命令的--permanent去掉(这个permanent选项是指永久打开端口,即重启机器也会自动打开端口,去掉后重启机器不会自动打开端口)

如果防火墙没有启动则会提示FirewallD is not running,启动防火墙命令:

systemctl start firewalld

14、连接工具测试是否成功连接数据库

本人使用Navicat Premium测试,输入ip地址和端口,用户和密码

猜你在找的CentOS相关文章