1.創建數據目錄
mkdir -pv /u01/app
mkdir -pv /u01/soft
mkdir -pv /u02/mysqldatamysql
2.創建用戶和組,受權
useradd -r mysql -s /sbin/nologin
chown -R mysql:mysql /u01/app/mysql
chown -R mysql:mysql /u02/mysqldatalinux
3.解壓連接文件
cd /u01/soft
tar -zxf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
ln -sv /u01/soft/mysql-5.7.10-linux-glibc2.5-x86_64 /u01/app/mysqlsql
4.初始化
cd /u01/app/mysql/bin
./mysqld --initialize --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql --explicit_defaults_for_timestamp
ls /u02/mysqldata/ #看生成的文件
./mysql_install_db --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql
記住臨時密碼數據庫
5.覆蓋配置文件
cp /u01/app/mysql/support-files/my-default.cnf /etc/my.cnf
cp /u01/app/mysql/support-files/mysql.server /etc/init.d/mysqld
vim /etc/my.cnf
vim /etc/profile.d/mysql.shvim
my.cnf: [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir=/u01/app/mysql datadir=/u02/mysqldata default_password_lifetime=0 character_set_server=utf8 skip-name-resolve #禁止DNS解析 max_connections = 800 max_connect_errors = 100 user=mysql port=3306 [mysql] default-character-set=utf8 mysql.sh: export MYSQL_HOME=/u01/app/mysql export PATH=$PATH:$MYSQL_HOME/bin
6. 更改密碼,刪除匿名用戶
update user set authentication_string=password('123123') where user='root' and Host='localhost'
ALTER USER 'root'@'localhost' IDENTIFIED BY '637h1m27h36r33K';安全
select Host,User,authentication_string,password_expired,password_lifetime from user; #查看用戶
ALTER USER 'root'@'%' IDENTIFIED BY '637h1m27h36r33K'; #設置用戶密碼
alter user root@'%' password expire never; #設置root用戶不過時
flush privilege;app
7. 廣泛用戶創建,受權
CREATE USER 'bicd'@'%' IDENTIFIED BY '71m32ch4n6317';
grant select,update on mysql.* to 'bicd'@'%';
SHOW GRANTS FOR bicd測試
8. 系統參數優化
vim /etc/security/limits.conf #修改文件句柄限制優化
fdisk -l
cat /sys/block/sda/queue/scheduler
echo deadline > /sys/block/sda/queue/scheduler #磁盤調度策略rest
9. 管理命令
/usr/local/mysql/bin/mysqladmin -u root -p shutdown #安全關閉數據庫
service mysqld start
service mysqld restart
df -h #查看磁盤
10.參數查看
show variables like '%innodb_file_per%'; #看是不是獨立表空間,爲on時是獨立表空間(數據文件不在一塊兒)
show variables like '%character_set_%'; #看數據庫字符集是啥玩意兒
show create database bicd; #看建庫過程
select @@sql_mode; #SQL模式,生產環境、測試環境統一使用嚴格模式
11. 詳細參數有待根據實際狀況調整。