6. MySQL

1、下载

# wgethttps://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz

2、依赖包安装

# yum install -y perl-Module-Install.noarch

#  yum install -y libaio

3、创建MySQL用户和组

3.1 创建MySQL目录

# mkdir /usr/local/mysql

3.2 新增MySQL用户组

# gourpadd mysql

3.3 新增mysql用户并设置不可用此账户登录终端

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

3.4 新增mysql用户和组对mysql根目录的读权限

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

4、安装

# tar zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz

# cd mysql-5.6.40-linux-glibc2.12-x86_64

# mv ./* /usr/local/mysql/

# cd /usr/local/mysql

# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

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

5、配置MySQL

5.1 复制配置文件到 /etc/my.cnf,替换原有的文件

# cp -a ./support-files/my-default.cnf /etc/my.cnf

5.2 编辑my.cnf

# vi /etc/my.cnf

[mysql]

default-character-set=utf8

socket=/var/lib/mysql/mysql.sock

[mysqld]

skip-name-resolve

port=3306

socket=/var/lib/mysql/mysql.sock

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

max_connections=200

max_allowed_packet=16M

[mysqld_safe]

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

pid-file=/var/run/mysqld/mysqld.pid

5.3 授权my.cnf

# chown 777 /etc/my.cnf

6、配置防火墙

7、启动MySQL服务

7.1 将mysql的服务脚本放到系统服务中

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

7.2 增加mysqld服务控制脚本执行权限

# chmod +x /etc/rc.d/init.d/mysqld

7.3 启动服务

# service mysqld start

7.4 查看状态

# ps aux | grep mysql

8、将mysql的bin目录加入PATH环境变量

# vi /etc/profile

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

export PATH

# source /etc/profile

# echo $PATH

9、root密码设置

9.1 登录

# /usr/local/mysql/bin/mysql -uroot

# mysql -uroot -p

mysql> use mysql;

mysql> update user set password=password('root') where user='root' and host='localhost';

mysql> flush privileges;

9.2 设置远程主机登录,用户名:shoper,密码:1234

mysql> GRANT ALL PRIVILEGES ON dbname.* TO 'shoper'@'%' IDENTIFIED BY '1234';

mysql> GRANT ALL PRIVILEGES ON dbname.* to shoper@localhost IDENTIFIED BY '1234';

mysql > flush privileges;

10、配置自动启动

# vi /etc/rc.d/rc.local

添加内容:

service mysqld start

你可能感兴趣的:(6. MySQL)