欢迎投稿

今日深度:

CenOS7下安装Mysql5.7,cenos7安装mysql5.7

CenOS7下安装Mysql5.7,cenos7安装mysql5.7


1. 删除CentOS自带mariadb

     检测是否装有mariadb

 

rpm -qa |grep mariadb
rpm -e --nodeps mariadb-libs-5.5.44-1.el7_1.x86_64

2.下载mysql 二进制安装包

    访问 https://dev.mysql.com/downloads/mysql/

执行命令:

 

# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz

    如果没有安装wget(已安装自动忽略)

#yum install wget

3. ls 查看文件,MD5校验文件完整性,tar解压文件

     通过MD5对比校验文件完整性

md5sum mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz 

     解压文件,并重命名为mysql

# tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
# mv mysql-5.7.15-linux-glibc2.5-x86_64 /usr/local/mysql

4. 进入MySQL目录 创建数据数据存储目录和日志目录

# cd ../mysql



 

# mkdir -p {data/mysql,/usr/log/mysql}

# touch /usr/log/mysql/mysql3306.err

5. 创建mysql用户组,添加mysql用户

 

 


 

# groupadd mysql

# useradd -r -g mysql mysql

# cat /etc/group | grep mysql

6. 更改mysql所属用户和组

# chown -R mysql /usr/mylocal/mysql 
# chown -R mysql /usr/mylocal/mysql/data
# chgrp -R mysql /usr/mylocal/mysql

7.进入mysql文件夹,配置参数,复制support-files文件下的my-default.cnf和mysql.server文件

配置参数

 

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

首次设置会生成临时密码,注意记录

# bin/mysql_ssl_rsa_setup --datadir=/data/mysql

复制文件到指定位置

# cp support-files/my-default.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysql

没有my-default.cnf 所以my.cnf 需要手动创建

配置文件如下:

# vim  /etc/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 一般配置选项
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
#socket=/tmp/mysqld.sock
character-set-server=utf8
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
log-error=/data/log/mysql/mysql3306.err
[client]

编辑mysqld 指定主路径

# vim /etc/init.d/mysqld

设置权限配置自启动

# chmod 755 /etc/init.d/mysql
# chkconfig --add mysql
# chkconfig --level 345 mysql on


8.将mysql路径添加至环境变量

# vim /etc/profile

使环境变量生效

# source /etc/profile

9.启动mysql

service mysqld start
mysql -uroot -p

输入第七步的临时密码

成功显示

mysql> use mysql;
mysql> update user set authentication_string=PASSWORD('root') where user='root';
mysql>  flush privileges;
mysql> exit;

如果无法修改,是因为mysql有个叫SQL_SAFE_UPDATES的变量,为了数据库更新操作的安全性,此值默认为1,所以才会出        现更新失败的情况。

mysql> set sql_safe_updates=off; 或  set sql_safe_updates=0;

查看状态

mysql> show variables like 'sql_safe%';

修改密码,mysql5.7的user没有password字段,用authentication_string 表示

mysql> update user set authentication_string=password('root') where User='root' and Host='localhost';
mysql> flush privileges;

至此,CentOS7下的MYSQL5.7的安装完毕

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

www.htsjk.Com true http://www.htsjk.com/mariadb/31729.html NewsArticle CenOS7下安装Mysql5.7,cenos7安装mysql5.7 1. 删除CentOS自带mariadb      检测是否装有mariadb   rpm -qa |grep mariadb rpm -e --nodeps mariadb-libs-5.5.44-1.el7_1.x86_64 2. 下载mysql 二进制安装包     访问 https:...
相关文章
    暂无相关文章
评论暂时关闭