1、新建用户组和用户
groupadd mysql
useradd mysql -g mysql
2、解压Mysql软件包
tar -zxvf /data/soft/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /data/webserver
3、重命名解压后的文件夹
cd /data/webserver
mv mysql-5.7.18-linux-glibc2.5-x86_64 mysql
4、创建数据目录
mkdir data
chown -R mysql:mysql /data/webserver/mysql/
chmod -R 755 /data/webserver/mysql/
5、初始化数据库
cd /data/webserver
./bin/mysqld --user=mysql --basedir=/data/webserver/mysql --datadir=/data/webserver/mysql/data --initialize
执行完命令后,会看到如下输出信息,注意记住root密码,后续步骤需要用到。
6、数据库配置-mysqld
cp /data/webserver/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vi /etc/init.d/mysqld
修改/etc/init.d/mysqld文件,正确设置basedir,datadir。
7、配置数据库-my.cnf
在/etc目录下创建my.cnf配置文件。
vi /etc/my.cnf
my.cnf配置文件内容如下:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# 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 = .....
basedir=/data/webserver/mysql
# datadir = .....
datadir=/data/webserver/mysql/data
# port = .....
# server_id = .....
# socket = .....
#socket=/tmp/mysql.sock
# 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
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
ft_min_word_len = 1
innodb_buffer_pool_size = 6G
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 2000
innodb_lock_wait_timeout = 5
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_logs = 128
innodb_flush_neighbors = 1
innodb_log_file_size = 4G
innodb_log_buffer_size = 16777216
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
8、修改密码
/data/webserver/mysql/bin/mysql -uroot -p
SET PASSWORD = PASSWORD('123456');
grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;
9、启动数据库
service mysqld start