一、首先安裝依賴包,避免在安裝過程當中出現問題mysql
# yum install gcc gcc-c++ kernel-devel ncurses-devel bison cmake # tar -zxvf boost_1_62_0.tar.gz # cp -r /opt/soft/boost_1_62_0 /usr/local/boost
二、建立mysql用戶及用戶組c++
# groupadd mysql # useradd -g mysql mysql
三、安裝mysqlsql
# tar zxvf mysql-5.7.16.tar.gz # cd mysql-5.7.16 # cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql-5.7.16 -DMYSQL_DATADIR=/data/mysqldata -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_BOOST=/usr/local/boost # make # make install
CMAKE參數說明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //默認安裝目錄
-DINSTALL_DATADIR=/usr/local/mysql/data //數據庫存放目錄
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校驗字符
-DEXTRA_CHARSETS=all //安裝全部擴展字符集
-DENABLED_LOCAL_INFILE=1 //容許從本地導入數據
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
注意事項:
如安裝失敗從新編譯時,須要清除舊的對象文件和緩存信息。數據庫
# make clean # rm -f CMakeCache.txt # rm -rf /etc/my.cnf
四、設置目錄權限並初始化數據庫緩存
# chown -R mysql.mysql /opt/mysql-5.7.16 # cp /opt/mysql-5.7.16/support-files/my-default.cnf /etc/my.cnf # cp /opt/mysql-5.7.16/support-files/mysql.server /etc/rc.d/init.d/mysqld(將mysql的啓動服務添加到系統服務中) # /opt/mysql-5.7.16/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql-5.7.16 --datadir=/data/mysqldata(初始化數據庫)
五、開啓mysql服務bash
# service mysqld start # chkconfig --add mysqld(加入開機啓動服務) # chkconfig mysqld on
七、登錄修改root密碼服務器
# /opt/mysql-5.7.16/bin/mysql -uroot -p(鏈接mysql,輸入初始化時生成的隨機密碼) mysql>alter user 'root'@'localhost' identified by 'abc123';
八、修改MySQL的root用戶密碼和受權用戶管理某個數據庫網絡
grant all on db_book.* to jack@'%' identified by 'abc123';(新建用戶帳號和密碼並受權用戶來管理某個數據庫) flush privileges; exit \s (查看服務器狀態) #mysql的一些簡單命令: show databases; use database; show tables; create database lufee; create table users(userid varchar(8),username varchar(8)); insert into users values('001','zhen'); insert into users values('002','jack'); select * from users; desc users;
備份:/opt/mysql/bin/mysqldump -uroot -p密碼 數據庫名 > data.bak
恢復:/opt/mysql/bin/mysql -uroot -p密碼 數據庫名 < data.bakdom
120726 11:57:22 [Warning] 'user' entry '@localhost.localdomain' ignored in --skip-name-resolve mode.
skip-name-resolve是禁用dns解析,避免網絡DNS解析服務引起訪問MYSQL的錯誤,通常應當啓用。
啓用後,在mysql的受權表中就不能使用主機名了,只能使用IP ,出現此警告是因爲mysql 表中已經存在有 localhost.localdomain 賬號信息。
咱們把它刪除就行了。socket
use mysql; delete from user where HOST='localhost.localdomain';
Query OK, 2 rows affected (0.00 sec)
重啓MYSQL ,發現警告已經沒有啦。
數據庫配置文件/etc/my.cnf 參考內容:
[mysqld] port=3306 user = mysql pid-file=/opt/mysql-5.6.22/mysql.pid socket=/tmp/mysql.sock basedir=/opt/mysql-5.6.22 datadir=/data/mysqldata tmpdir=/data/mysqltmp skip-external-locking lower_case_table_names = 1 skip-name-resolve key_buffer_size=512M max_allowed_packet=32M table_open_cache=2048 sort_buffer_size=2M read_buffer_size=2M myisam_sort_buffer_size=64M thread_cache_size=64 query_cache_size=0 wait_timeout=3600 interactive_timeout=3600 max_connections=1500 max_connect_errors=99999999999 event-scheduler=on log-bin-trust-function-creators=1 explicit_defaults_for_timestamp=true ##############binlog#################################### binlog_format=row expire_logs_days=5 max_binlog_size=512M ##############errorlog################################## log-error=/opt/mysql-5.6.22/log/mysql.err #############Innodb###################################### innodb_buffer_pool_size=512M innodb_buffer_pool_instances=32 innodb_log_file_size=512M innodb_log_buffer_size=32M innodb_log_files_in_group =4 innodb_lock_wait_timeout=50 innodb_file_io_threads=4 innodb_flush_method=O_DIRECT innodb_print_all_deadlocks=1 innodb_file_format=Barracuda ################Slow log#################################### slow_query_log_file=/opt/mysql-5.6.22/log/slow-query.log long_query_time=3 slow_query_log=1 ####################general log############################## general_log_file=/opt/mysql-5.6.22/log/general.log #####################Replication############################ server-id=1 log_slave_updates binlog-ignore-db=mysql,test relay_log_recovery=1 skip_slave_start=true slave_compressed_protocol=on log-bin=mysql-bin replicate-wild-ignore-table=mysql.% innodb_strict_mode=1 #auto_increment_offset=2 ##the variables is not needed with this system #auto_increment_increment=2 ##the variables is not needed with this system ############################################################# sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysqldump] quick max_allowed_packet=32M [mysql] #no-auto-rehash #prompt=\U|d> [myisamchk] sort_buffer_size=256M read_buffer=2M write_buffer=2M [mysqlhotcopy] interactive-timeout