1.下载mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
2.解压并更改移动
tar -xzvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
- 移动mysql文件夹
mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql
4.创建mysql数据文件夹
mkdir /data/mysql
5.创建mysql用户
groupadd mysql
useradd -r -g mysql mysql
6.加上mysql用户权限
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
chown -R mysql /data/mysql
7.创建配置文件
vim /etc/my.cnf
#复制以下内容
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/data/mysql/mysqld.pid
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
8.初始化数据库
cd /data/mysql
chmod 777 mysqld.log
chown mysql:mysql mysqld.log
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
查看mysqld.log可看到初始密码
9.创建mysql的pid
cd /data/mysql
touch mysqld.pid
chmod 777 mysqld.pid
10.设置开机自启
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
11.启动服务
service mysqld start/stop/restart
12.登录mysql并修改密码
mysql -hlocalhost -uroot -p+“初始密码”
>password=password('passwd');
13.创建外部权限
grant all privileges on *.* to 'root'@'%' identified by 'passwd';
flush privileges;
网友评论