環(huán)境:Linux系統(tǒng)
mysql編譯安裝
關(guān)閉防火墻和selinux
1到忽、編譯安裝mysql5.7
1、清理安裝環(huán)境:
# yum erase mariadb mariadb-server mariadb-libs mariadb-devel -y
# userdel -r mysql
# rm -rf /etc/my*
# rm -rf /var/lib/mysql
2清寇、創(chuàng)建mysql用戶
[root@mysql-server ~]# useradd -r mysql -M -s /bin/false
3喘漏、從官網(wǎng)下載tar包
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.27.tar.gz
4、安裝編譯工具
# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make
cmake:
# yum -y install cmake
5华烟、創(chuàng)建mysql目錄
[root@mysql-server ~]# mkdir -p /usr/local/{data,mysql,log}
6翩迈、解壓
[root@mysql-server ~]# tar xzvf mysql-boost-5.7.27.tar.gz -C /usr/local/
注:如果安裝的MySQL5.7及以上的版本,在編譯安裝之前需要安裝boost,因?yàn)楦甙姹緈ysql需要boots庫(kù)的安裝才可以正常運(yùn)行盔夜。否則會(huì)報(bào)CMake Error at cmake/boost.cmake:81錯(cuò)誤
安裝包里面自帶boost包
7帽馋、編譯安裝
cd 解壓的mysql目錄
[root@mysql-server ~]# cd /usr/local/mysql-5.7.27/
[root@mysql-server mysql-5.7.27]#cmake . \
-DWITH_BOOST=boost/boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
提示:boost也可以使用如下指令自動(dòng)下載,如果不下載bost壓縮包比吭,把下面的這一條添加到配置中第二行
-DDOWNLOAD_BOOST=1/
參數(shù)詳解:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ 安裝目錄
-DSYSCONFDIR=/etc \ 配置文件存放 (默認(rèn)可以不安裝配置文件)
-DMYSQL_DATADIR=/usr/local/mysql/data \ 數(shù)據(jù)目錄 錯(cuò)誤日志文件也會(huì)在這個(gè)目錄
-DINSTALL_MANDIR=/usr/share/man \ 幫助文檔
-DMYSQL_TCP_PORT=3306 \ 默認(rèn)端口
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ sock文件位置绽族,用來(lái)做網(wǎng)絡(luò)通信的,客戶端連接服務(wù)器的時(shí)候用
-DDEFAULT_CHARSET=utf8 \ 默認(rèn)字符集衩藤。字符集的支持吧慢,可以調(diào)
-DEXTRA_CHARSETS=all \ 擴(kuò)展的字符集支持所有的
-DDEFAULT_COLLATION=utf8_general_ci \ 支持的
-DWITH_READLINE=1 \ 上下翻歷史命令
-DWITH_SSL=system \ 使用私鑰和證書(shū)登陸(公鑰) 可以加密。 適用與長(zhǎng)連接赏表。壞處:速度慢
-DWITH_EMBEDDED_SERVER=1 \ 嵌入式數(shù)據(jù)庫(kù)
-DENABLED_LOCAL_INFILE=1 \ 從本地倒入數(shù)據(jù)检诗,不是備份和恢復(fù)匈仗。
-DWITH_INNOBASE_STORAGE_ENGINE=1 默認(rèn)的存儲(chǔ)引擎,支持外鍵
1566127257697.png
[root@mysql-server mysql-5.7.27]# make && make install
如果安裝出錯(cuò)逢慌,想重新安裝:
不用重新解壓悠轩,只需要?jiǎng)h除安裝目錄中的緩存文件CMakeCache.txt
1566127465783.png
需要很長(zhǎng)時(shí)間!大約半小時(shí)
8攻泼、初始化
[root@mysql-server mysql-5.7.27]# cd /usr/local/mysql
[root@mysql-server mysql]# chown -R mysql.mysql .
[root@mysql-server mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ---初始化完成之后火架,一定要記住提示最后的密碼用于登陸或者修改密碼
1566133517087.png
初始化,只需要初始化一次
[root@mysql-server ~]# vim /etc/my.cnf ---添加如下內(nèi)容
[mysqld]
basedir=/usr/local/mysql #指定安裝目錄
datadir=/usr/local/mysql/data #指定數(shù)據(jù)存放目錄
1566133805284.png
9、啟動(dòng)mysql
[root@mysql-server ~]# cd /usr/local/mysql
[root@mysql-server mysql]# ./bin/mysqld_safe --user=mysql &
1566133918969.png
10忙菠、登錄mysql
[root@mysql-server mysql]# /usr/local/mysql/bin/mysql -uroot -p'GP9TKGgY9i/8'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27
Copyright (c) 2000, 2019, 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> exit
11何鸡、修改密碼
[root@mysql-server mysql]# /usr/local/mysql/bin/mysqladmin -u root -p'GP9TKGgY9i/8' password 'Duan@123'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
修改密碼不成功,提示密碼過(guò)期牛欢,需要使用原碼登陸MySQL然后執(zhí)行:
mysql>set password = "new password";
12骡男、添加環(huán)境變量
[root@mysql-server mysql]# vim /etc/profile ---添加如下
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[root@mysql-server mysql]# source /etc/profile
之后就可以在任何地方使用mysql命令登陸Mysql服務(wù)器:
[root@mysql-server mysql]# mysql -uroot -p'QianFeng@123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.27 Source distribution
Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>exit
13、配置mysqld服務(wù)的管理工具:
[root@mysql-server mysql]# cd /usr/local/mysql/support-files/
[root@mysql-server support-files]# cp mysql.server /etc/init.d/mysqld
[root@mysql-server support-files]# chkconfig --add mysqld
[root@mysql-server support-files]# chkconfig mysqld on
先將原來(lái)的進(jìn)程殺掉
[root@mysql-server ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@mysql-server ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1087/sshd
tcp6 0 0 :::22 :::* LISTEN 1087/sshd
tcp6 0 0 :::3306 :::* LISTEN 31249/mysqld
[root@mysql-server ~]# /etc/init.d/mysqld stop
數(shù)據(jù)庫(kù)編譯安裝完成.
yum安裝MySQL
關(guān)閉防火墻和selinux
mysql的官方網(wǎng)站:www.mysql.com
1566135397943.png
拉到底
1566135423896.png
1566135475994.png
1566135502131.png
1566135543502.png
1566136040912.png
下載
[root@mysql-server ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
或者下載到本地上傳到服務(wù)器
2.安裝mysql的yum倉(cāng)庫(kù)
[root@mysql-server ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
[root@mysql-server ~]# yum -y install yum-utils #安裝yum工具包
3傍睹、配置yum源
[root@mysql-server ~]# vim /etc/yum.repos.d/mysql-community.repo #修改如下
1566136558444.png
1表示開(kāi)啟隔盛,0表示關(guān)閉
或者
# yum-config-manager --enable mysql57-community 將禁用的yum源庫(kù)啟用
# yum-config-manager --disable mysql80-community 將啟用的yum源庫(kù)禁用
4、安裝數(shù)據(jù)庫(kù)
[root@mysql-server ~]# yum install -y mysql-community-server
啟動(dòng)服務(wù)
[root@mysql-server ~]# systemctl start mysqld
設(shè)置開(kāi)機(jī)啟動(dòng)
[root@mysql-server ~]# systemctl enable mysqld
5拾稳、查找密碼
密碼保存在日志文件中
[root@mysql-server ~]# grep password /var/log/mysqld.log
2019-08-18T14:03:51.991454Z 1 [Note] A temporary password is generated for root@localhost: woHtkMgau9,w
6吮炕、修改密碼
[root@mysql-server ~]# mysql -uroot -p'woHtkMgau9,w' #登錄
兩種方式:
第一種:
mysql> alter user 'root'@'localhost' identified by 'Duan@123';
[root@mysql-server ~]# mysql -uroot -p'woHtkMgau9,w'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27
....
mysql> alter user 'root'@'localhost' identified by 'Duan@123';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@mysql-server ~]# mysql -uroot -p'Duan@123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
...
mysql> exit
Bye
第二種:
# mysqladmin -u root -p'舊密碼' password '新密碼'
注:修改密碼必須大小寫(xiě)數(shù)字和特殊符號(hào)都有。
修改密碼不成功熊赖,提示密碼過(guò)期,需要使用原碼登陸MySQL然后執(zhí)行:
mysql>set password = "new password";
擴(kuò)展
通過(guò)配置文件設(shè)置密碼強(qiáng)度虑椎,生產(chǎn)環(huán)境中一般不予許使用
[root@mysql-server ~]# vim /etc/my.cnf #在最后添加如下內(nèi)容
validate_password=off
[root@mysql-server ~]# systemctl restart mysqld #重啟mysql生效
可以用第二種方式修改為簡(jiǎn)單的密碼:
[root@mysql-server ~]# mysqladmin -uroot -p'QianFeng@123' password 'qf123'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@mysql-server ~]# mysql -uroot -pqf123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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> exit
Bye
編譯安裝:
# ls
COPYING README bin include mysql-test support-files
COPYING-test README-test docs lib share
1震鹉、bin目錄
用于放置一些可執(zhí)行文件,如mysql捆姜、mysqld传趾、mysqlbinlog等。
2泥技、include目錄
用于放置一些頭文件浆兰,如:mysql.h、mysql_ername.h等珊豹。
3簸呈、lib目錄
用于放置一系列庫(kù)文件。
4店茶、share目錄
用于存放字符集蜕便、語(yǔ)言等信息。
yum安裝:
/var/lib/mysql 存放數(shù)據(jù)文件
/usr/share/mysql 用于存放字符集贩幻、語(yǔ)言等信息轿腺。