Linux安裝MySQL的兩種方法

原文鏈接:http://blog.csdn.net/superchanon/article/details/8546254

---------------------------------------------------------------------------------------


1.?????? 運行平臺:CentOS 6.3 x86_64,基本等同于RHEL 6.3

2.?????? 安裝方法:

安裝MySQL主要有兩種方法:一種是通過源碼自行編譯安裝,這種適合高級用戶定制MySQL的特性,這里不做說明;另一種是通過編譯過的二進制文件進行安裝。二進制文件安裝的方法又分為兩種:一種是不針對特定平臺的通用安裝方法,使用的二進制文件是后綴為.tar.gz的壓縮文件;第二種是使用RPM或其他包進行安裝,這種安裝進程會自動完成系統的相關配置,所以比較方便。

3.?????? 下載安裝包:

a.? 官方下載地址:

http://dev.mysql.com/downloads/mysql/#downloads

或鏡像文件下載:

http://dev.mysql.com/downloads/mirrors.html

2.? 下載文件(根據操作系統選擇相應的發布版本):

a.? 通用安裝方法

mysql-5.5.29-linux2.6-x86_64.tar.gz

b.?????? RPM安裝方法:

MySQL-server-5.5.29-2.el6.x86_64.rpm

MySQL-client-5.5.29-2.el6.x86_64.rpm

4.?????? 通用安裝步驟

a.?????? 檢查是否已安裝,grep的-i選項表示匹配時忽略大小寫

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

*可見已經安裝了庫文件,應該先卸載,不然會出現覆蓋錯誤。注意卸:載時使用了--nodeps選項,忽略了依賴關系:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

b.???? 添加mysql組和mysql用戶,用于設置mysql安裝目錄文件所有者和所屬組。

[root@localhost JavaEE]#groupadd mysql

[root@localhost JavaEE]#useradd -r -g mysql mysql

*useradd -r參數表示mysql用戶是系統用戶,不可用于登錄系統。

c.? 將二進制文件解壓到指定的安裝目錄,我們這里指定為/usr/local

[root@localhost ~]# cd/usr/local/

[root@localhost local]#tar zxvf /path/to/mysql-5.5.29-linux2.6-x86_64.tar.gz

*加壓后在/usr/local/生成了解壓后的文件夾mysql-5.5.29-linux2.6-x86_64,這名字太長,我們為它建立一個符號鏈接mysql,方便輸入。

[root@localhost local]#ln -s mysql-5.5.29-linux2.6-x86_64 mysql

d.???? /usr/local/mysql/下的目錄結構

Directory

Contents of Directory

bin

Client programs and the?mysqld?server

data

Log files, databases

docs

Manual in Info format

man

Unix manual pages

include

Include (header) files

lib

Libraries

scripts

mysql_install_db

share

Miscellaneous support files, including error messages, sample configuration files, SQL for database installation

sql-bench

Benchmarks

e.???? 進入mysql文件夾,也就是mysql所在的目錄,并更改所屬的組和用戶。

[root@localhost local]#cd mysql

[root@localhost mysql]#chown -R mysql .

[root@localhost mysql]#chgrp -R mysql .

f.?????? 執行mysql_install_db腳本,對mysql中的data目錄進行初始化并創建一些系統表格。注意mysql服務進程mysqld運行時會訪問data目錄,所以必須由啟動mysqld進程的用戶(就是我們之前設置的mysql用戶)執行這個腳本,或者用root執行,但是加上參數--user=mysql。

[root@localhost mysql]scripts/mysql_install_db --user=mysql

*如果mysql的安裝目錄(解壓目錄)不是/usr/local/mysql,那么還必須指定目錄參數,如

[root@localhost mysql]scripts/mysql_install_db --user=mysql \

???????? --basedir=/opt/mysql/mysql \

???????? --datadir=/opt/mysql/mysql/data

*將mysql/目錄下除了data/目錄的所有文件,改回root用戶所有,mysql用戶只需作為mysql/data/目錄下所有文件的所有者。

[root@localhost mysql]chown -R root .

[root@localhost mysql]chown -R mysql data

g.???? 復制配置文件

[root@localhost mysql] cp support-files/my-medium.cnf /etc/my.cnf

h.? 將mysqld服務加入開機自啟動項。

*首先需要將scripts/mysql.server服務腳本復制到/etc/init.d/,并重命名為mysqld。

[root@localhostmysql]? cp support-files/mysql.server /etc/init.d/mysqld

*通過chkconfig命令將mysqld服務加入到自啟動服務項中。

[root@localhost mysql]#chkconfig --add?mysqld

*注意服務名稱mysqld就是我們將mysql.server復制到/etc/init.d/時重命名的名稱。

*查看是否添加成功

[root@localhost mysql]#chkconfig --list mysqld

mysqld? ?0:off 1:off????????2:on????????3:on????????4:on????????5:on????????6:off

i.? 重啟系統,mysqld就會自動啟動了。

*檢查是否啟動

[root@localhost mysql]#netstat -anp|grep mysqld

tcp??????? 0?????0 0.0.0.0:3306???????????????0.0.0.0:*?????????????????? LISTEN????? 2365/mysqld????????

unix? 2?????[ ACC ]???? STREAM???? LISTENING???? 14396?2365/mysqld????????/tmp/mysql.sock

*如果不想重新啟動,那可以直接手動啟動。

[root@localhost mysql]#service mysqld start

Starting MySQL.. SUCCESS!

j.?????? 運行客戶端程序mysql,在mysql/bin目錄中,測試能否連接到mysqld。

[root@localhost mysql]#/usr/local/mysql/bin/mysql

Welcome to the MySQLmonitor.? Commands end with ; or \g.

Your MySQL connection idis 2

Server version:5.5.29-log MySQL Community Server (GPL)

?

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql> quit

Bye

*此時會出現mysql>命令提示符,可以輸入sql語句,輸入quit或exit退出。為了避免每次都輸入mysql的全路徑/usr/local/mysql/bin/mysql,可將其加入環境變量中,在/etc/profile最后加入兩行命令:

MYSQL_HOME=/usr/local/mysql

export PATH=$PATH:$MYSQL_HOME/bin

這樣就可以在shell中直接輸入mysql命令來啟動客戶端程序了

[root@localhost mysql]#mysql

Welcome to the MySQLmonitor.? Commands end with ; or \g.

Your MySQL connection idis 3

Server version:5.5.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its

affiliates. Other namesmay be trademarks of their respective

owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql>

?

第二種方法?

?RPM安裝步驟

a.?????? 檢查是否已安裝,grep的-i選項表示匹配時忽略大小寫

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

可見已經安裝了庫文件,應該先卸載,不然會出現覆蓋錯誤。注意卸載時使用了--nodeps選項,忽略了依賴關系:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

2.???? 安裝MySQL的服務器端軟件,注意切換到root用戶:

[root@localhost JavaEE]#rpm -ivh MySQL-server-5.5.29-2.el6.x86_64.rpm

安裝完成后,安裝進程會在Linux中添加一個mysql組,以及屬于mysql組的用戶mysql。可通過id命令查看:

[root@localhost JavaEE]#id mysql

uid=496(mysql)gid=493(mysql) groups=493(mysql)

MySQL服務器安裝之后雖然配置了相關文件,但并沒有自動啟動mysqld服務,需自行啟動:

[root@localhost JavaEE]#service mysql start

Starting MySQL.. SUCCESS!

可通過檢查端口是否開啟來查看MySQL是否正常啟動:

[root@localhost JavaEE]#netstat -anp|grep 3306

tcp??????? 0?????0 0.0.0.0:3306???????????????0.0.0.0:*?????????????????? LISTEN????? 34693/mysqld

c.? 安裝MySQL的客戶端軟件:

[root@localhost JavaEE]#rpm -ivh MySQL-client-5.5.29-2.el6.x86_64.rpm

如果安裝成功應該可以運行mysql命令,注意必須是mysqld服務以及開啟:

[root@localhost JavaEE]#mysql

Welcome to the MySQLmonitor.? Commands end with ; or \g.

Your MySQL connection idis 1

Server version: 5.5.29MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademarkof Oracle Corporation and/or its affiliates. Other names may be trademarks oftheir respective owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql>

d.? RPM安裝方式文件分布

Directory

Contents of Directory

/usr/bin

Client programs and scripts

/usr/sbin

The?mysqld?server

/var/lib/mysql

Log files, databases

/usr/share/info

Manual in Info format

/usr/share/man

Unix manual pages

/usr/include/mysql

Include (header) files

/usr/lib/mysql

Libraries

/usr/share/mysql

Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation

/usr/share/sql-bench

Benchmarks

?

?

---------2016-08-26--松門一枝花補充--------

但我安裝時報錯:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

-----安裝好serve的時候,有下面的提示:-----

適合5.7之前的版本。之后的請移步此處

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.


You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.


Also, the account for the anonymous user has been removed.


In addition, you can run:


? /usr/bin/mysql_secure_installation


which will also give you the option of removing the test database.
This is strongly recommended for production servers.


See the manual for more instructions.


Please report any problems at http://bugs.mysql.com/


The latest information about MySQL is available on the web at


? http://www.mysql.com


Support MySQL by buying support/licenses at http://shop.mysql.com


New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings


進入:mysql_secret?

適合5.7之前的版本。之后的請移步此處

[root@hello110 ~]# cat .mysql_secret?
# The random password set for the root user at Sat Aug 27 01:33:41 2016 (local time): RsD3_afVuO4zOSxi


用里面的密碼登錄:


[root@hello110 hello]# mysql -uroot -pRsD3_afVuO4zOSxi ? ??

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 15
Server version: 5.6.32


Copyright (c) 2000, 2016, 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>?


mysql> set password = password('123456');
Query OK, 0 rows affected (0.16 sec)


修改密碼后,就可以使用了。大笑


mysql>?



本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/539295.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/539295.shtml
英文地址,請注明出處:http://en.pswp.cn/news/539295.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

jenkins 手動執行_想知道如何用Jenkins自動執行Python腳本輸出測試報告?

前言在用python做自動化測試時,我們寫好代碼,然后需要執行才能得到測試報告,這時我們可以通過 Jenkins 來進一步完成自動化工作。借助Jenkins,我們可以結合 Git/SVN 自動拉取代碼,可以設置定時構建,接著就可…

VR 影院,約嗎?

世界第一家 VR 影院已經開張,朋友,去不? 世界第一家 VR 影院正式開張 (無大屏的 VR 電影院) 在被稱為 VR 元年的 2016 年,越來越多的人加入了這個新興的領域,各種傳統應用也在被 VR 包裝之后以…

redis cluster 分布式鎖_關于分布式鎖原理的一些學習與思考redis分布式鎖,zookeeper分布式鎖...

首先分布式鎖和我們平常講到的鎖原理基本一樣,目的就是確保,在多個線程并發時,只有一個線程在同一刻操作這個業務或者說方法、變量。在一個進程中,也就是一個jvm 或者說應用中,我們很容易去處理控制,在jdk …

會計行業被計算機取代馬云,會計人:為什么我神煩“人工智能取代說”?

原標題:會計人:為什么我神煩“人工智能取代說”?原創來源:學會計有方法從財會機器人誕生到馬云的無人商店,全行業掀起了一股“人工智能取代說”的熱潮。有些財會朋友在一輪又一輪的信息轟炸下,倍感壓力&…

mysql5.6允許遠程服務器訪問數據庫

創建一個mysql用戶,并設置可以遠程訪問 grant usage on *.* to fredlocalhost identified by fred;//創建用戶fred密碼ferdselect host,user,password from mysql.user where userfred;//查看記錄 grant all privileges on *.* to fred%identified by fred;//設置可以遠程訪問…

sp烘焙流程_小手雷-PBR材質流程(一)——(基本材質)

小手雷-PBR材質流程(一)Substance Painter生存手冊經過了12個章節的講解后,已經完結了(。・ω・。)相信大家經過了生存手冊這一基礎教程過后,對Substance Painter這款軟件已經有了比較堅實的基礎了,…

MyBatis-進階2

typeHandler typeHandler有什么用? 你可以重寫類型處理器或創建你自己的類型處理器來處理不支持的或非標準的類型。 具體做法為:實現 org.apache.ibatis.type.TypeHandler 接口, 或繼承一個很便利的類 org.apache.ibatis.type.BaseTypeHandle…

python中 r是什么意思_python中rb含義理解

Python文件讀寫的幾種模式: r,rb,w,wb 那么在讀寫文件時,有無b標識的的主要區別在哪里呢? 文件使用方式標識 r:默認值,表示從文件讀取數據 w:表示要向文件寫入數據,并截斷以前的內容 a:表示要向文件寫入數據&#xff0…

哈佛大學計算機生物科學,生命科學專業

【出國留學網】昨日,泰晤士報公布了最新版2018年世界大學生命科學排名,哈佛大學位列第一。本文是關于世界各國大學在本次生命科學排名中的具體表現,供你選校參考。The 2018 Times Higher Education World University Rankings’ table for li…

怎樣呵護友誼_呵護真正的友情,助力漫長的人生

友情,即友誼,是指朋友和朋友之間的感情。它是一種很美妙的東西,可以讓你在失落的時候變得高興起來,可以讓你走出苦海,去迎接新的人生。它就像一種你無法說出又可以感到快樂無比的東西。只有擁有真正朋友的人&#xff0…

【Day41】Python之路——AJAX

什么是AJAX AJAX Asynchronous JavaScript and XML(異步的 JavaScript 和 XML)。 優點: 不重新加載整個頁面的情況下,可以與服務器交換數據并更新部分網頁內容 不需要任何瀏覽器插件,但需要用戶允許JavaScript在瀏覽器上執行 同源…

LINUX重啟MYSQL的命令

原文:http://blog.csdn.net/liuyong0818/article/details/5693336 ------------------------原文有錯誤,本文轉載時已修改--------- 如何啟動/停止/重啟MySQL 一、啟動方式 1、使用 service 啟動:service mysql start 2、使用 mysql 腳…

html css子標簽,HTML+CSS系列:CSS選擇器(標簽、ID、類、通配符、后代、子元素、并集、偽類)...

一.標簽選擇器Documenth1 {color: red;}h2{color: green;}Hello World!Hello World!Hello !Hello !二.類選擇器Document.box {color: green;}.box1 {font-size: 26px;}Hello World!Hello World!三.ID選擇器Document#box{color: green;}Hello World!四.通配符選擇器Document*{ma…

aes離線解密工具_如何在Python中解密OpenSSL AES加密文件?

OpenSSL為AES加密提供了一種流行的(但不安全 - 見下文!)命令行界面:openssl aes-256-cbc -salt -in filename -out filename.encPython以PyCrypto包的形式支持AES,但它只提供工具。如何使用Python / PyCrypto解密使用OpenSSL加密的文件&#…

什么是Hive

Hive 是建立在 Hadoop 上的數據倉庫基礎構架。 它提供了一系列的工具,可以用來進行數據提取轉化加載(ETL ),這是一種可以存儲、查詢和分析存儲在 Hadoop 中的大規模數據的機制。 Hive 定義了簡單的類 SQL 查詢語言&#xff0c…

VUE-搜索過濾器

VUE非常實用的搜索過濾&#xff0c;喜歡點個贊哦 廢話不多說&#xff0c;先來看看效果 1 引入vue <script src"https://cdn.jsdelivr.net/npm/vue"></script>2 HTML <div id"app"><input v-modelsearch /><ul v-if"search…

單選按鈕必填會有紅色選中提示嗎_為什么單選按鈕和復選框不能共存?

以下內容由摹客團隊翻譯整理&#xff0c;僅供學習交流&#xff0c;摹客設計協作一站式云平臺&#xff0c;從產品、設計到開發&#xff0c;摹客來解決。單選按鈕和復選框長期以來一直都是容易導致用戶困惑的組件。這兩個組件通常用于相同的情景下&#xff0c;但看起來又完全不同…

用計算機進行服裝設計,電腦服裝設計(10制版1班)

《電腦服裝設計》課程教學大綱課程名稱:電腦服裝設計(Corldraw和Photoshop)課程代碼:10617313總學時&#xff1a;68課時適用專業&#xff1a;10制版方向學生開課單位&#xff1a;時裝設計學院一、講課內容第一章 CORELDROW軟件整體的介紹第一節緒論, 與其他圖形繪制軟件的區別及…

程序包org.junit.jupiter.api不存在

在跑項目的時候遇到這個問題&#xff0c;去看pom文件一切正常&#xff0c;也引入了這個依賴 <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope&…

thrift介紹及應用(一)—介紹

原文&#xff1a;http://blog.csdn.net/guxch/article/details/12157151 ------------------------------------------------------------------------------------ 一、概述 Thrift是Apache下的一個子項目&#xff0c;最早是Facebook的項目&#xff0c;后來Facebook提供給Apa…