MySQL5.7安裝(RPM)筆記
1. 檢查MySQL是否安裝,如果有安裝,則移除(rpm –e 名稱)
[root@localhost ~]# rpm -qa | grep -i mysql
mysql-libs-xxxxxxxxxx.x86_64
[root@localhost ~]# yum -y remove mysql-libs* --nodeps --force
2. 安裝MySQL,並修改配置文件位置
[root@localhost rpm]# rpm -ivh mysql-community-common-5.7.22-1.el6.x86_64.rpm
[root@localhost rpm]# rpm -ivh mysql-community-libs-5.7.22-1.el6.x86_64.rpm
[root@localhost rpm]# rpm -ivh mysql-community-client-5.7.22-1.el6.x86_64.rpm
[root@localhost rpm]# rpm -ivh mysql-community-server-5.7.22-1.el6.x86_64.rpm
3.修改配置/etc/my.cnf文件,修改數據存放路徑、mysql.sock路徑以及默認編碼utf-8.
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
# ###################公共參數#########################################
# basedir = .....
datadir = /home/mysql/data
port = 3306
# server_id = .....
socket =/var/lib/mysql/mysql.sock
log-error=/home/mysql/log/mysqld.log
pid-file=/home/mysql/mysqld.pid
# ###################主要參數#########################################
sql_mode=STRICT_TRANS_TABLES
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
symbolic-links=0
# ###################其它參數#########################################
# 緩存innodb打開的數據. 建議,專用服務器設置:70%, 其它設置: 10%.
innodb_flush_log_at_trx_commit = 0
innodb_buffer_pool_size = 1024M
innodb_log_buffer_size = 8M
innodb_log_file_size = 4G
# 操作DDL/DML/DCL產生的2進制格式log日誌,用於主從服務器之間的同步數據
server-id=97
log_bin = master-bin
log_bin_index=master-bin.index
# relay_log=slave-bin
# relay_log_index=slave-bin.index
binlog_do_db=system
# 慢查詢日誌
slow_query_log=1
long_query_time=10
slow_query_log_file=/home/mysql/log/log-slow-queries.log
# 字符集
character_set_server = utf8
collation_server = utf8_general_ci
# mysql安裝完後, 表名默認區大小寫. 0: 區分大小寫; 1: 不區分大小寫.
lower_case_table_names = 1
# 最大連接數,默認:151(允許的最大連接數16384).
max_connections = 1000
# 包的最大限制
max_allowed_packet=20M
# 免密碼登入
# skip-grant-tables
4. 初始化MySQL,設置密碼,允許遠程登陸
[root@localhost rpm]# service mysqld start
mysql> use mysql;
mysql> select host, user, authentication_string , password_expired from user;
+-----------+---------------+-------------------------------------------+------------------+
| host | user | authentication_string | password_expired |
+-----------+---------------+-------------------------------------------+------------------+
| localhost | root | *7D0F7C5410B4AB7A25365AA269DB9DBA3FEFF74B | Y |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N |
+-----------+---------------+-------------------------------------------+------------------+
mysql> update user set authentication_string=password(‘123456‘) where user=‘root‘;
mysql> update user set host=‘%‘ where user=‘root‘ and host=‘localhost‘;
mysql> update user set password_expired=‘N‘;
mysql> flush privileges;
mysql> exit
註意:
1, 免密碼登入方式(skip-grant-tables)啟動,密碼設置後禁用免密碼登入方式
2, password_expired 為Y表示過期, N表示未過期;註意:
5. 設置開機自啟動
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig --list | grep mysql
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
6. MySQL的默認安裝位置
/var/lib/mysql/ #數據庫目錄
/usr/share/mysql #配置文件目錄
/usr/bin #相關命令目錄
/etc/init.d/mysqld #啟動腳本
7. 常用命令
啟動: service mysql start
停止: service mysql stop
查看狀態: service mysql status
導入數據:LOAD DATA LOCAL INFILE ‘/home/package/script/table_data.csv‘ INTO TABLE table_name COLUMNS TERMINATED BY ‘,‘ LINES TERMINATED BY ‘\r\n‘;
鏈接數據庫:mysql -uroot -p密碼
MySQL5.7安裝(RPM)筆記