一母截、Mysql安裝

環(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ǔ)言等信息轿腺。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末两嘴,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子族壳,更是在濱河造成了極大的恐慌憔辫,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,386評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件仿荆,死亡現(xiàn)場(chǎng)離奇詭異贰您,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)竞穷,“玉大人钉赁,你說(shuō)我怎么就攤上這事⊙募纾” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,704評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)返劲。 經(jīng)常有香客問(wèn)我,道長(zhǎng)栖茉,這世上最難降的妖魔是什么篮绿? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,702評(píng)論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮吕漂,結(jié)果婚禮上亲配,老公的妹妹穿的比我還像新娘。我一直安慰自己惶凝,他們只是感情好吼虎,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,716評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著苍鲜,像睡著了一般思灰。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上混滔,一...
    開(kāi)封第一講書(shū)人閱讀 51,573評(píng)論 1 305
  • 那天洒疚,我揣著相機(jī)與錄音,去河邊找鬼坯屿。 笑死油湖,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的领跛。 我是一名探鬼主播肺魁,決...
    沈念sama閱讀 40,314評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼隔节!你這毒婦竟也來(lái)了鹅经?” 一聲冷哼從身側(cè)響起寂呛,我...
    開(kāi)封第一講書(shū)人閱讀 39,230評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎瘾晃,沒(méi)想到半個(gè)月后贷痪,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,680評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蹦误,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,873評(píng)論 3 336
  • 正文 我和宋清朗相戀三年劫拢,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片强胰。...
    茶點(diǎn)故事閱讀 39,991評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡舱沧,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出偶洋,到底是詐尸還是另有隱情熟吏,我是刑警寧澤,帶...
    沈念sama閱讀 35,706評(píng)論 5 346
  • 正文 年R本政府宣布玄窝,位于F島的核電站牵寺,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏恩脂。R本人自食惡果不足惜帽氓,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,329評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望俩块。 院中可真熱鬧黎休,春花似錦、人聲如沸玉凯。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,910評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)壮啊。三九已至嫉鲸,卻和暖如春撑蒜,著一層夾襖步出監(jiān)牢的瞬間歹啼,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,038評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工座菠, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留狸眼,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,158評(píng)論 3 370
  • 正文 我出身青樓浴滴,卻偏偏與公主長(zhǎng)得像拓萌,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子升略,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,941評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容