安裝MYSQLmysql
本人安裝的系統版本信息(Esxi虛擬機)
[lsug@172-16-1-105 ~]$ uname -a
Linux 172-16-1-105 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[lsug@172-16-1-105 ~]$ cat /etc/redhat-release
CentOS release 6.7 (Final)linux
一,編譯安裝所需的工具和庫
yum install gcc gcc-c++ ncurses-devel perl cmake -yc++
二,新增mysql用戶和組
useradd mysql -s /sbin/nologin -M sql
三,下載軟件並安裝
下載
wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.34.tar.gzvim
解壓
tar -zxf mysql-5.6.34.tar.gz
cd mysql-5.6.34
編譯
cmake . -DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_DATADIR=/data/mysql/data \
-DMYSQL_UNIX_ADDR=/data/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLIATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0socket
make && make install工具
編譯my.cnf(這是咱們的開發測試環境配置的參數,你能夠根據本身的環境調試)
vim /etc/my.cnf測試
[mysqld]
port = 3306
socket = /data/mysql/tmp/mysql.sock
datadir = /data/mysql/data
user = mysql
server_id=38253
replicate_wild_ignore_table = db_check.%
replicate_wild_ignore_table = information_schema.%
replicate_wild_ignore_table = performance_schema.%
back_log = 500
max_connections = 4500
max_user_connections = 3000
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connect_errors = 50000
#character_set_filesystem = utf8
collation_server = utf8_bin
character_set_server = utf8
interactive_timeout = 31536000
wait_timeout = 50400
skip_name_resolve = 1
innodb_file_per_table = 1
table_open_cache = 4096
table_definition_cache = 4096
max_allowed_packet = 16M
#binlog_cache_size = 2M
#binlog_stmt_cache_size = 1M
#binlog_rows_query_log_events = 1
max_heap_table_size = 64M
tmp_table_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 64
####thread_concurrency = 16
thread_stack = 256K
#query_cache_size = 64M
#query_cache_type = 0
#query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = INNODB
transaction_isolation = REPEATABLE-READ
#log-bin = /data/mysql/data/binlog
#relay_log = /data/mysql/data/relaylog
binlog_format = row
expire_logs_days = 30
log_slave_updates
slow_query_log
long_query_time = 1
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 32G
innodb_data_file_path = ibdata1:1G:autoextend
#innodb_write_io_threads = 4
#innodb_read_io_threads = 2
#innodb_thread_concurrency = 8
innodb_thread_concurrency = 64
innodb_flush_log_at_trx_commit = 0
#sync_binlog = 0
innodb_log_buffer_size = 8M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 75
innodb_lock_wait_timeout = 10
innodb_old_blocks_time= 1000
innodb_stats_on_metadata = 0
tmpdir = /data/mysql/tmpui
#thread_pool_oversubscribe = 8
#slave_parallel_threads = 8
#innodb_buffer_pool_instances = 4
innodb_buffer_pool_dump_at_shutdown = 1
innodb_buffer_pool_load_at_startup = 1
####extra_max_connections = 10
####extra_port = 33061
innodb_print_all_deadlocks = 1
#innodb_io_capacity = 4000
innodb_io_capacity = 2000
#innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
#innodb_flush_neighbors = 0
#innodb_lru_scan_depth = 2048
#slave-skip-errors=1062
explicit_defaults_for_timestamp=1es5
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
prompt="\\u@\\h:\\d \\R:\\m:\\s> "
default-character-set = utf8
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
--------------------------
mkdir -p /data/mysql/tmp/
修改權限文件
chown -R mysql.mysql /data/mysql
進入安裝路徑,執行初始化配置腳本
cd /data/mysql
./scripts/mysql_install_db --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data/
注:在啓動MySQL服務時,會按照必定次序搜索my.cnf,
先在/etc目錄下找,找不到則會搜索"$basedir/my.cnf",
在本例中就是,本人放置在/etc/my.cnf
注意:在CentOS 6.4版操做系統的最小安裝完成後,在/etc目錄下會存在一個my.cnf,須要將此文件改名爲其餘的名字,如:/etc/my.cnf.bak,不然,該文件會干擾源碼安裝的MySQL的正確配置,形成沒法啓動。
添加服務,拷貝服務腳本到init.d目錄,並設置開機啓動
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
啓動msyql並檢查狀態
[root@localhost mysql]# /etc/init.d/mysql start
Starting MySQL........ SUCCESS!
[root@localhost mysql]# /etc/init.d/mysql status
SUCCESS! MySQL running (32356)
MySQL啓動成功後,root默認沒有密碼,咱們須要設置root密碼。
設置以前,咱們須要先設置PATH,要否則不能直接調用mysql
修改/etc/profile文件,在文件末尾添加
export PATH=/data/mysql/bin:$PATH
讓配置當即生效
source /etc/profile
如今,咱們能夠在終端內直接輸入mysql,進入mysql的環境了
執行下面的命令修改root密碼
mysql -uroot
mysql> SET PASSWORD = PASSWORD('123456');
若要設置root用戶能夠遠程訪問,執行
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
-----------編譯報錯解決------(網上搜集)----------
1.若make出現相似錯誤:
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".
CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
代表make未安裝,執行:sudo apt-get install -y make
參見: Mysql 錯誤以及解決辦法
2.若是make到63%左右出現錯誤:
make[2]: *** [storage/perfschema/unittest/pfs_connect_attr-t] Error 1
make[1]: *** [storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/all] Error 2
則:cmake去掉-DWITH_PARTITION_STORAGE_ENGINE=1參數從新編譯
參見: 通用MYSQL5.5和5.6源碼包安裝
3.MySQL啓動報錯:
[ERROR] InnoDB: The system tablespace must be writable!
[ERROR] Plugin 'InnoDB' init function returned error.
則:rm -rf /usr/local/mysql/data/ib_logfile*
編譯參數及安裝過程: Linux源碼安裝mysql 5.6.12 (cmake編譯)
4.其餘錯誤: Ubuntu 12 下的Mysql 5.5的 cmake 源碼編譯安裝
5.編譯錯誤:configure: error: No curses/termcap library found
查找文件系統:find / -name libncursesw*
若是找到則從新編譯並加上如下參數:
--with-named-curses-libs=/lib/i386-linux-gnu/libncursesw.so.5.9
或者安裝libncurses5-dev包:
sudo apt-cache search libncurses5 && sudo apt-get install -y libncurses5-dev
6.make出現錯誤:collect2: ld returned 1 exit status 嘗試以下解決方案: sudo apt-get install -f sudo apt-get update sudo apt-get dist-upgrade sudo apt-get install -f build-essential libncurses5-dev libncurses5