下面所有的操作均在root下进行
1.设置mysql组和用户
groupadd mysql
useradd -g mysql -d /home/mysql mysql
password mysql //修改密码
2.下载安装包
mkdir /usr/local/mysql //建立安装目录
cd /usr/local/mysql
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz //下载安装包
gzip -d mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz //解压安装包
tar xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar //解包安装包
mv -f mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz .../.
chown -R mysql:mysql mysql //修改mysql目录下的所有文件的属主为mysql
cd /var/log
touch mysqld.log
chown mysql:mysql mysqld.log
chmod 777 mysqld.log
#执行如下操作开启mysql服务,以及设置相关权限 cd /var/run/ mkdir mysqld chmod 777 mysqld cd mysqld vim mysqld.pid chmod 777 mysqld.pid chown mysql:mysql mysqld.pid
3.建立mysql配置文件
touch /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=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/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'
4.依赖包安装
yum install libaio
yum install numactl
5.初始化数据库
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
6.查看初始密码
cat /var/log/mysqld.log
最后一行:root@localhost: 这里就是初始密码
7.设置开机自动启动mysql任务
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start //启动服务
8.修改密码
set password=password('新密码');
flush privileges;
UPDATE `mysql`.`user` SET `Host` = '%', `User` = 'root' WHERE (`Host` = 'localhost') AND (`User` = 'root');