mysql源碼安裝
阿新 • • 發佈:2018-10-20
ets my.cnf配置 csdn 無法 iptable color extern format readline
1、卸載舊版本 [root@host-test-huanqiu ~]# rpm -qa | grep mysql mysql-5.1.73-7.el6.x86_64 mysql-libs-5.1.73-7.el6.x86_64 mysql-server-5.1.73-7.el6.x86_64 #普通刪除模式 [root@host ~]# rpm -e mysql-5.1.73-7.el6.x86_64 mysql-libs-5.1.73-7.el6.x86_64 mysql-server-5.1.73-7.el6.x86_64 # 強力刪除模式,如果使用上面命令刪除時,提示有依賴的其它文件,則用該命令可以對其進行強力刪除 [root@host~]# rpm -e --nodeps mysql-5.1.73-7.el6.x86_64 mysql-libs-5.1.73-7.el6.x86_64 mysql-server-5.1.73-7.el6.x86_64 #刪除/etc/my.cnf [root@host~]# rm /etc/my.cnf
2、安裝編譯代碼需要的包 [root@host ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel
3、創建mysql用戶,不建立mysql用戶家目錄(加-M參數),也就是禁用mysql賬號登陸系統 [root@host~]# groupadd mysql [root@host ~]# useradd -g mysql mysql -M -s /sbin/nologin
4、下載MySQL,源碼編譯安裝 [root@host ~]# cd /usr/local/src [root@host src]# wget -c http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.38.tar.gz [root@host src]# tar -zxvf mysql-5.6.38.tar.gz [root@host src]# cd mysql-5.6.38/ [root@host mysql-5.6.38]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci [root@host mysql-5.6.38]# make && make install
5、配置MySQL 修改/usr/local/mysql權限 [root@host mysql-5.6.38]# mkdir -p /data/mysql/data [root@host mysql-5.6.38]# chown -R mysql:mysql /usr/local/mysql [root@host mysql-5.6.38]# chown -R mysql:mysql /data/mysql/data 執行初始化配置腳本,創建系統自帶的數據庫和表 [root@host mysql-5.6.38]# cd /usr/local/mysql [root@host mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql //如果後續不小心刪除了這個數據目錄或這個目錄下的文件被誤操作刪除了,還可以利用這個命令重新初始化
需要特別註意:
在啟動MySQL服務時,會按照一定次序搜索my.cnf,先在/etc目錄下找,找不到則會搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,這是新版MySQL的配置文件的默認位置!
另外:
在CentOS 6.4版操作系統最小安裝完成後,默認會在/etc目錄下存在一個my.cnf,需要將此文件更名為其他的名字,如:/etc/my.cnf.bak,否則,該文件會幹擾源碼安裝的MySQL的正確配置,造成無法啟動。
在使用"yum update"更新系統後,需要檢查下/etc目錄下是否會多出一個my.cnf,如果多出,將它重命名成別的。否則,MySQL將使用這個配置文件啟動,可能造成無法正常啟動等問題。
----------------------------------------------------------------------------------------------------------------------------------
啟動MySQL 添加服務,拷貝服務腳本到init.d目錄,並設置開機啟動 [root@host mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@host mysql]# chkconfig mysql on [root@host mysql]# service mysql start //啟動前,要先配置my.cnf文件(如下), 並確保/data/mysql/data和/usr/local/mysql的mysql權限
如果啟動報錯: [root@slave-server mysql]# service mysql start Starting MySQL.Logging to ‘/data/mysql/data/mysql-error.log‘. 170416 12:55:28 mysqld_safe Directory ‘/usr/local/mysql/var‘ for UNIX socket file don‘t exists. ERROR! The server quit without updating PID file (/data/mysql/data/mysql.pid). 解決辦法: [root@slave-server mysql]# mkdir /usr/local/mysql/var [root@slave-server mysql]# chown -R mysql:mysql /usr/local/mysql [root@slave-server mysql]# service mysql start Starting MySQL.. SUCCESS!
配置用戶和環境變量 MySQL啟動成功後,root默認沒有密碼,需要設置root密碼,設置之前,需要先設置PATH,否則不能直接調用mysql 修改/etc/profile文件,在文件末尾添加 [root@host mysql]# vim /etc/profile ........ export PATH=$PATH:/usr/local/mysql/bin [root@host mysql]# source /etc/profile 到此,就可以直接mysql登陸了 [root@host mysql]# mysql -uroot
登陸mysql,若是報錯如下: [root@test2-235 mysql]# mysql ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2) 解決辦法 [root@test2-235 mysql]# mkdir /var/lib/mysql/ [root@test2-235 mysql]# ln -s /usr/local/mysql/var/mysql.sock /var/lib/mysql/mysql.sock
修改root密碼,執行命令如下 mysql> SET PASSWORD = PASSWORD(‘123456‘); 若要設置root用戶可以遠程訪問,執行 mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘password‘ WITH GRANT OPTION; 使授權立即生效 mysql> FLUSH PRIVILEGES; 也可以使用mysqladmin命令設置mysql密碼 [root@hostu mysql]# mysqladmin password 123456 #安裝mysql後第一次設置密碼 [root@host-test-huanqiu mysql]# mysqladmin -p 舊密碼 password 新密碼 #重置密碼
最後配置防火墻 默認防火墻的3306端口默認沒有開啟,若要遠程訪問,需要開啟這個端口.也可以做下白名單,比如只允許192.168.1.0/24網段的客戶機訪問本機的mysql。 [root@host mysql]# vim /etc/sysconfig/iptables ....... -A INPUT -s 192.168.1.0/24 -p tcp -m tcp -m state --state NEW -dport 3306 -j ACCEPT
下面貼下mysql6.x的my.cnf配置 [client] port = 3306 socket = /usr/local/mysql/var/mysql.sock [mysqld] port = 3306 socket = /usr/local/mysql/var/mysql.sock basedir = /usr/local/mysql/ datadir = /data/mysql/data pid-file = /data/mysql/data/mysql.pid user = mysql bind-address = 0.0.0.0 server-id = 1 sync_binlog=1 log_bin = mysql-bin skip-name-resolve back_log = 600 max_connections = 3000 max_connect_errors = 3000 table_open_cache = 512 max_allowed_packet = 16M binlog_cache_size = 16M max_heap_table_size = 16M tmp_table_size = 256M read_buffer_size = 1024M read_rnd_buffer_size = 1024M sort_buffer_size = 1024M join_buffer_size = 1024M key_buffer_size = 8192M thread_cache_size = 8 query_cache_size = 512M query_cache_limit = 1024M ft_min_word_len = 4 binlog_format = mixed expire_logs_days = 30 log_error = /data/mysql/data/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /data/mysql/data/mysql-slow.log performance_schema = 0 explicit_defaults_for_timestamp skip-external-locking default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 4096M #這個參數一般設置為服務器最大內存的60% innodb_write_io_threads = 1000 innodb_read_io_threads = 1000 innodb_thread_concurrency = 8 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 4M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 8M myisam_max_sort_file_size = 2G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 [mysqldump] quick max_allowed_packet = 16M [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M read_buffer = 4M write_buffer = 4M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES port = 3306
原文鏈接:https://blog.csdn.net/stoytoz/article/details/79213932
mysql源碼安裝