19. Linux MySQL安装(CentOS -7)

Linux MySQL5.7.13 安装教程

Authorxushuyi

 

借鉴Linux Ret Hat 6.7系统 MySQL安装,本文档适用于 CentOS - 7 系统环境。

 

1. 系统约定

1、安装包下载目录:/data/software

2、MySQL安装目录位置:/usr/local/mysql

3、数据库保存位置:/data/mysql

4、日志保存位置:/data/log/mysql

5、检查磁盘大小:df -h

2. 下载MySQL

1、官网地址:https://dev.mysql.com/downloads/mysql/

2、阿里提供下载地址:http://ftp.kaist.ac.kr/mysql/Downloads/?spm=a2c6h.12873639.0.0.142042dfZFX7yg

2、执行命令如下:

#mkdir /data/software

#cd /data/software

#wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz

#wget http://ftp.kaist.ac.kr/mysql/Downloads/MySQL-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

3、解压压缩包到目标位置

# mkdir /usr/local/mysql

#cd /dat/software

#pwd

执行后如下:

 

 

#ls

 

 

#cd /usr/local

#pwd

 

 

# tar -xzvf /data/software/mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz

 

 

 

#ls

 

 

--修改文件名

# mv mysql-5.7.13-linux-glibc2.5-x86_64 mysql         

#ls

 

 

 

4、创建数据仓库目录

--/data/mysql 数据仓库目录

# mkdir /data/mysql         

#ls /data/

 

 

3. 安装MySQL

1、新建mysql用户、组及目录

# groupadd mysql

# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql

 

 

---新建 msyql用户禁止登录shell

2、改变目录属有者

#cd /usr/local/mysql

#pwd

#chown -R mysql .

#chgrp -R mysql .

 

 

#chown -R mysql /data/mysql/

3、配置参数

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

 

 

此处需要注意记录生成的临时密码,如上文:*gre1Y::Q<A-

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

 

 

4、修改系统配置文件

 

 

#cp my-default.cnf /etc/my.cnf

#cp mysql.server /etc/init.d/mysql

 

 

#vim /etc/init.d/mysql

修改以下内容:

 

 

#vim /etc/my.cnf

修改以下内容:

 

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]
skip-name-resolve
lower_case_table_names=1
# max_connections = 2000
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = /var/lib/mysql/
# port = .....
# server_id = .....
# socket = .....

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
log_error = /data/log/mysql/error.log
#err-log = /var/log/mysqld.log
#pid-file = /var/lib/mysql/localhost.localdomain.pid

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

 

 

 

 

 

 

5、启动MySQL

 

 

#bin/mysqld_safe --user=mysql &

 

 

 

异常:

 

 

查看日志:cat /data/log/mysql/error.log

 

 

 

再次执行:#bin/mysqld_safe --user=mysql &

日志还是报错,如下

 

 

解决方案参照:http://blog.csdn.net/chenjiayi_yun/article/details/16920967

赋予/data 权限:chmod -R 777 /data

但是重启 查看日志还是报错

删除/data/mysql 中的 ibdata1 ib_logfile0 ib_logfile1

 

 

如果日志还报错,那就不采用这种安全模式启动,直接启动mysql

命令如下:

/etc/init.d/mysql start

ps -ef | grep mysql

 

 

MySQL正常启动

 

bin/mysql --user=root -p

--输入第6步生成的临时密码

 

 

 

 

mysql>set password=password('123456');

 

 

mysql>grant all privileges on *.* to root@'%' identified by '123456';

mysql>flush privileges;

 

 

mysql>use mysql;

mysql>select host,user from user;

 

 

6、添加系统路径

#vim /etc/profile

添加:

export PATH=/usr/local/mysql/bin:$PATH

如下:

 

 

#source /etc/profile

 

7、配置MySQL自动启动

#chmod 755 /etc/init.d/mysql

#chkconfig --add mysql

#chkconfig --level 345 mysql on

8、重启mysql

/etc/init.d/mysql restart

9、删除MySQL安装包

命令类似如下:

rpm -ev mysql-libs-5.1.73-5.el6_6.x86_64 --nodeps

 

10、忘记密码情况

cd /usr/local/mysql/bin

mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

mysql -u root mysql

进入mysql之后

use mysql

update mysql.user set authentication_string = password("123456") where user="root";

flush privileges;

quit;

 

posted @ 2017-10-21 20:12  xu_shuyi  阅读(160)  评论(0)    收藏  举报