mysql5.6.28安裝教程分享
1、在安裝MySQL-5.6.28.tar.gz前,先安裝編譯環(huán)境
2、編譯安裝mysql
2.1 添加用戶
1
2
|
groupadd mysql useradd -g mysql mysql |
2.2 編譯安裝
1
2
3
4
5
|
tar -zxvf mysql-5.6.28. tar .gz #默認(rèn)情況下是安裝在/usr/local/mysql cd mysql-5.6.28 cmake . -LH (使用默認(rèn)屬性編譯) make && make install |
2.3.1 編譯參數(shù)的設(shè)定
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
cmake . -DCMAKE_INSTALL_PREFIX= /usr/local/mysql -DMYSQL_DATADIR= /usr/local/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= /tmp/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; |
2.3.2 完整版
1
2
3
4
5
|
cmake . -DCMAKE_INSTALL_PREFIX= /usr/local/mysql -DMYSQL_DATADIR= /usr/local/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= /tmp/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; |
2.4 改變mysql安裝目錄的所有者
1
2
|
chown -R mysql:mysql /usr/local/mysql #讓mysql用戶,具有寫的權(quán)限(默認(rèn)具有) |
3、初始化數(shù)據(jù)庫(kù)
1
2
|
cd /usr/local/mysql/scripts . /mysql_install_db --user=mysql --basedir= /usr/local/mysql --datadir= /usr/local/mysql/data |
4、將mysql的配置文件拷貝到/etc/my.cnf
1
2
3
4
5
6
7
8
9
10
11
|
#使用默認(rèn)配置文件 cd /usr/local/mysql/support-files cp my-default.cnf /etc/my .cnf #修改配置文件,添加下面的內(nèi)容 #socket適用于,通信的,一定要添加 #socket的位置和cmake時(shí)mysql的-DMYSQL_UNIX_ADDR=/tmp/mysql.sock的路徑,socket的路徑地址要和前面的地址一樣(不然mysql服務(wù)不能正常啟動(dòng).) basedir = /usr/local/mysql datadir = /usr/local/mysql/data pid- file = /usr/local/mysql/data/mysql .pid user = mysql socket= /tmp/mysql .sock |
5、將mysql服務(wù),添加到系統(tǒng)服務(wù)里面,并設(shè)置開啟自啟動(dòng)
1
2
3
4
5
6
7
8
9
10
|
cd /usr/local/mysql/support-files #注冊(cè)服務(wù) cp mysql.server /etc/rc .d /init .d /mysql #讓chkconfig管理mysql服務(wù) chkconfig --add mysql #開機(jī)啟動(dòng) chkconfig mysql on |
6、啟動(dòng)Mysql服務(wù)
1
2
3
4
5
|
service mysql start #驗(yàn)證mysql啟動(dòng)成功 netstat -ant | grep 3306 |
7、配置mysql用戶,修改root密碼
Mysql啟動(dòng)成功后,root默認(rèn)沒有密碼,我們需要設(shè)置root密碼。
設(shè)置root密碼之前,先設(shè)置PATH路徑,以便能直接調(diào)用/usr/local/mysql/bin中的mysql等命令.
修改/etc/profile文件,在文件末尾加入
1
2
|
PATH= /usr/local/mysql/bin :$PATH export PATH |
關(guān)閉文件,運(yùn)行下面的命令,讓配置立即生效
source /etc/profile
關(guān)于怎么修改root用戶密碼1:
1
2
|
#將'new-password'改成自己的密碼 /usr/local/mysql/bin/mysqladmin -u root password 'new-password' |
關(guān)于怎么修改root用戶密碼2:
現(xiàn)在,參考博客,地址是http://www.jfrwli.cn/article/83890.html
使用root用戶登錄mysql:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#要輸入的密碼,就是上面設(shè)置的密碼 [root@VM_13_53_centos support-files] # mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 Server version: 5.6.28 Source distribution Copyright (c) 2000, 2015, 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> |
若要設(shè)置root用戶可以遠(yuǎn)程訪問(wèn),執(zhí)行
1
2
3
|
#將下面的'password'改成自己的密碼 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root' @ '%' IDENTIFIED BY 'password' WITH GRANT OPTION; mysql> flush privileges; |
9、關(guān)閉防火墻,防止遠(yuǎn)程連接失敗
1)重啟后生效
開啟: chkconfig iptables on
關(guān)閉: chkconfig iptables off
2)立即生效
開啟: service iptables start
關(guān)閉: service iptables stop
3)開放3306端口
1
2
3
|
vi /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT service iptables restart |
10、改變編碼,防止亂碼
SHOW VARIABLES LIKE 'character%'
修改mysql的、etc/my.cnf文件
1
2
3
4
5
6
7
8
|
[client] default-character- set =utf8 [mysqld] character- set -server=utf8 [mysql] default-character- set =utf8 |
11、可能出現(xiàn)的錯(cuò)誤
問(wèn)題1:Starting MySQL..The server quit without updating PID file ([FAILED]/mysql/Server03.mylinux.com.pid).
解決:
修改/etc/my.cnf 添加socket的配置
問(wèn)題2:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解決:
新建一個(gè)鏈接或在mysql中加入-S參數(shù),直接指出mysql.sock位置。
1
2
|
ln -s /usr/local/mysql/data/mysql .sock /tmp/mysql .sock /usr/local/mysql/bin/mysql -u root -S /usr/local/mysql/data/mysql .sock |
12、Mysql的下載:https://pan.baidu.com/s/1jHXOzMe
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。