Mysql5.6.26源碼編譯安裝

安裝依賴包ncurses-devel和編譯工具cmake

[root@shenxiang67 ~]# yum install ncurses-devel cmake –y

建立mysql執行賬戶和數據目錄

[root@shenxiang67 ~]# useradd -u 3366 -s /sbin/nologin mysql 
[root@shenxiang67 ~]# mkdir /data

解壓源碼包並從新配置安裝信息

  • 解壓源碼包與配置
[root@shenxiang67 download]# tar zxf mysql-5.6.26.tar.gz 
[root@shenxiang67 download]# cd mysql-5.6.26
[root@shenxiang67 mysql-5.6.26]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data \
-DMYSQL_USER=mysql
  • 參數說明

-DCMAKE_INSTALL_PREFIX                  # 數據文件存放目錄
-DMYSQL_UNIX_ADDR                        # sock文件路徑
-DDEFAULT_CHARSET                          # 默認字符集
-DDEFAULT_COLLATION                      # 默認字符校對
-DWITH_EXTRA_CHARSETS                  # 擴展字符支持 默認all
-DWITH_storage_STORAGE_ENGINE    # 存儲引擎的支持,默認支持MyISAM,MERGE,MEMORY,CVS存儲引擎
-DENABLED_LOCAL_INFILE=1             # 啓用加載本地數據
-DMYSQL_DATADIR                            # 數據存放目錄
-DMYSQL_USER                                   # mysql運行用戶mysql

  • 擴展

-DWITH_PARTITION_STORAGE_ENGINE=1      #支持分區表
-DINSTALL_LIBDIR=dir_name Library               #庫目錄
-DSYSCONFDIR=dir_name                                #The default my.cnf option file directorysql

編譯和安裝

[root@shenxiang67 mysql-5.6.26]# echo $? 
0 
[root@shenxiang67 mysql-5.6.26]# make -j 4 && make install

初始設置mysql服務

  • 受權用戶
[root@shenxiang67 mysql-5.6.26]# chown -R mysql:mysql /usr/local/mysql/
[root@shenxiang67 mysql-5.6.26]# chown -R mysql:mysql /data
[root@shenxiang67 mysql-5.6.26]# chmod 1777 /tmp
  • 配置環境變量
[root@shenxiang67 mysql-5.6.26]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile 
[root@shenxiang67 mysql-5.6.26]# source !$ 
source /etc/profile
  • 建立配置文件和啓動腳本,並開機自啓
[root@shenxiang67 mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnf   #添加配置文件 
cp: overwrite `/etc/my.cnf'? y 
[root@shenxiang67 mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld   #添加啓動腳本 
[root@shenxiang67 mysql-5.6.26]# chmod +x /etc/init.d/mysqld   #給腳本添加執行權限 
[root@shenxiang67 mysql-5.6.26]# vim /etc/init.d/mysqld   #修改服務啓動腳本的兩個參數 
basedir=/usr/local/mysql   #MySQL安裝目錄 
datadir= /data   #數據存放目錄 
[root@shenxiang67 mysql-5.6.26]# chkconfig mysqld on   #添加開機啓動

初始化數據庫

[root@shenxiang67 mysql-5.6.26]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data --user=mysql
 
Installing MySQL system tables... 
OK 
Filling help tables... 
OK 
…..省略

啓動mysql服務

[root@shenxiang67 mysql-5.6.26]# /etc/init.d/mysqld start 
Starting MySQL.. SUCCESS!

注:必須初始化數據庫纔可去啓動,不然報錯。數據庫

初始化安全配置

[root@shenxiang67 mysql-5.6.26]# mysql_secure_installation #安全初始化配置
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL 
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! 
In order to log into MySQL to secure it, we'll need the current 
password for the root user. If you've just installed MySQL, and 
you haven't set the root password yet, the password will be blank, 
so you should just press enter here. 

Enter current password for root (enter for none): 初始無密碼 直接按空格 
OK, successfully used password, moving on... 

Setting the root password ensures that nobody can log into the MySQL 
root user without the proper authorisation. 
Set root password? [Y/n] y 建立超級用戶密碼 
New password: 
Re-enter new password: 
Password updated successfully! 
Reloading privilege tables.. 
... Success! 

By default, a MySQL installation has an anonymous user, allowing anyone 
to log into MySQL without having to have a user account created for 
them. This is intended only for testing, and to make the installation 
go a bit smoother. You should remove them before moving into a 
production environment. 
Remove anonymous users? [Y/n] y 刪除匿名用戶 
... Success! 

Normally, root should only be allowed to connect from 'localhost'. This 
ensures that someone cannot guess at the root password from the network. 
Disallow root login remotely? [Y/n] y 拒絕超級用戶遠程登錄 
... Success! 

By default, MySQL comes with a database named 'test' that anyone can 
access. This is also intended only for testing, and should be removed 
before moving into a production environment. 
Remove test database and access to it? [Y/n] y 刪除測試數據庫和訪問嗎? 
- Dropping test database... 
... Success! 
- Removing privileges on test database... 
... Success! 

Reloading the privilege tables will ensure that all changes made so far 
will take effect immediately. 
Reload privilege tables now? [Y/n] y 如今從新加載權限表嗎? 
... Success! 

Cleaning up... 
All done! If you've completed all of the above steps, your MySQL 
installation should now be secure.
 
Thanks for using MySQL!

登錄測試

[root@shenxiang67 mysql-5.6.26]# mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 9 
Server version: 5.6.26-log Source distribution 
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 
Oracle is a registered trademark of Oracle Corporation and/or its 
affiliates. Other names may be trademarks of their respective 
owners. 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> select user,host from mysql.user; 全部命令必須以「;」結束而去執行 
+------+-----------+ 
| user | host | 
+------+-----------+ 
| root | 127.0.0.1 | 
| root | ::1 | 
| root | localhost | 
+------+-----------+ 
3 rows in set (0.00 sec)
 
mysql>


常見問題

  • 問題1

Starting MySQL.. ERROR! The server quit without updating PID file (/data/shenxiang66.pid).
出如今這問題的緣由是:無初始化數據庫而啓動mysql服務vim


解決:從新初始化數據庫便可安全

  • 問題2

Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)bash


解決:
pkill mysqld 幹掉mysql進程
rm -rf /data/* 刪除data中全部數據
從新初始化工具

相關文章
相關標籤/搜索