linuxmysql安裝教程
查看伺服器是否有自帶的MySQL,如果有可以直接使用,如果自帶的版本比較低,可以刪除然後安裝自己想要的版本 (在安裝新版本MySQL之前,需要卸載伺服器自帶的MySQL包和MySQL資料庫分支mariadb的包)
1、rpm -qa|grep mysql -- 查詢伺服器是否有mysql,如有,則執行下面的語句進行刪除
2、rpm -qa |grep mariadb -- 查詢伺服器是否有mariadb,有則執行第三步進行刪除
3、rpm -e --nodeps 要刪除的文件名( nodeps表示強制刪除 )
小貼士1: 如果使用rz命令時提示找不到命令,直接執行: yum -y install lrzsz 則可以在線下載。
命令: rz 或者rz -be
格式: rz -be 選擇需要上傳的文件
批量或者單個上傳文件,通過ZMODEM協議,除此之外,還可以通過ftp或者sftp進行上傳
按照下面的命令順序執行,文件名修改成你壓縮後的文件名稱即可
啟動命令: systemctl start mysql
報錯信息: Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
根據報錯信息執行 : systemctl status mysqld.service" 或者 "journalctl -xe"命令查看報錯詳情,發現報錯信息中存在: Data Dictionary upgrade from MySQL 5.7 in progress 。
說明是因為新版本和之前伺服器自帶的版本對應的包存在沖突,刪除對應的沖突目錄即可,執行: rm -rf /var/lib/mysql/*(執行刪除命令的時候要看清楚哦)
systemctl start mysql -- 啟動伺服器
第一次成功啟動MySQL會被設置默認一個密碼,通過以下命令查看並進行登錄。
1、查看第一次啟動的臨時密碼 :grep password /var/log/mysqld.log
2、連接到伺服器 : mysql -u root -p 回車,然後輸出密碼
3、第一次連接會強制你必須修改連接密碼 ,可以使用以下的語句進行修改密碼:
ALTER USER root@localhost IDENTIFIED WITH caching_sha2_password BY ' (MySQL8.x適合使用這個語句)
UPDATE USER SET PASSWORD=PASSWORD('你的密碼') WHERE USER='root' (MySQL5.x版本的修改)
② 如何在linux下安裝mysql
第一步:進入mysql官方網站
第二步:選擇MySQL Community Server(GPL)
第三步:進入下載頁面,會看到Mysql Community Server 5.6.17選擇自己的linux版本,我的是ubuntu14.04,選擇Linux-Generic,把頁面往下翻,選擇Linux-Generic(glibc 2.5)(x86,64-bit), Compressed TAR Archive下載
第四步:點擊下載之後會出現oracle的登陸界面,注冊用戶後登陸oracle賬號,即可免費下載mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz
第五步:下載之後文件在/home/liubei/下載 目錄下,打開命令行,對文件夾進行解壓,給這么長的文件夾起個別名,找到mysql提供的官方安裝指導,具體代碼:
第五步代碼:
shell>cd /usr/local
shell>sudo tar zxvf /home/liubei/下載/mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz
shell>sudo ln -s mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz mysql
shell>cd mysql
shell>ls
第六步:通過上面的操作你就能看到mysql文件夾裡面的INSTALL-BINARY文件,用gedit將其打開,代碼如下
第六步代碼:
shell>gedit INSTALL-BINARY
第七步:這個文檔中會有如下圖所示的一段代碼,如下,接下來我分析文檔里的代碼,和我自己安裝過程中的一些問題,和我的安裝代碼
第八步:
文檔安裝代碼:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysqlshell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
第九步:
文檔安裝代碼中每一行的意思:
shell> groupadd mysql //在/etc/group文件中添加mysql的記錄
shell> useradd -r -g mysql mysql
shell> cd /usr/local //打開/usr/local目錄
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz // /path/to/mysql-VERSION-OS.tar.gz指下載的文件的具體路徑我的是 /home/liubei/下載/mysql-5.6.17-linux-glibc2.5-x86_64.tar.gz
//這個步驟解壓下載的mysql壓縮文件到/usr/local文件夾下
shell> ln -s full-path-to-mysql-VERSION-OS mysql //為很長的文件夾取個別名並創建鏈接
shell> cd mysql //打開mysql文件夾
shell> chown -R mysql . //注意後面有個點,意思是把文件夾的own許可權賦予mysql用戶shell> chgrp -R mysql . //後面也有點,意思是把文件夾的grp許可權賦予mysql用戶,文件夾的許可權可以通過
shell>ls -la查看
shell> scripts/mysql_install_db --user=mysql //通過mysql用戶安裝mysql
shell> chown -R root . //把文件夾的own許可權賦予root
shell> chown -R mysql data //把data文件夾的own許可權賦予mysql
shell> bin/mysqld_safe --user=mysql &//啟動mysql
shell> cp support-files/mysql.server /etc/init.d/mysql.server //復制mysql.server文件到/etc/init.d目錄下
第十步:因為我是新裝的ubuntu系統,所以在安裝過程中遇到很多問題,按教程中的不能完全成功,接下來貼出我自己的安裝命令:
第十步安裝命令:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> sudo scripts/mysql_install_db --user=mysql
這一步之後sudo gedit my.cnf
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql --datadir=/usr/local/mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
第十一步:
各行中的命令的意思:
shell> groupadd mysqlshell> useradd -r -g mysql mysqlshell> cd /usr/local
//實際在做解壓到/usr/local目錄下是需要管理員許可權的如下:
shell>sudo tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> sudo ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
//給文件夾賦予許可權的命令都需要管理員許可權shell> sudo chown -R mysql .
shell> sudo chgrp -R mysql .
shell> sudo scripts/mysql_install_db --user=mysql
//新系統在執行上面這行代碼時會報錯,按照報錯中的提示安裝所需插件即可
//這一步之後sudo gedit my.cnf ,修改mysql的啟動信息,如下圖所示
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql --datadir=/usr/local/mysql/data &
//上面這步總是報錯後在後面加上 --datadir參數後成功啟動mysql
//這一步進行後即可成功啟動mysql,輸入
shell>mysql
如果出現如下圖所示,即啟動mysql成功
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
第十二步:
另外:關閉mysql的命令
shell>sudo service mysqld stop
然後啟動mysql的命令
shell> sudo service mysqld start
③ linux伺服器怎麼安裝mysql
linux安裝mysql服務分兩種安裝方法:
①源碼安裝,優點是安裝包比較小,只有十多M,缺點是安裝依賴的庫多,安裝編譯時間長,安裝步驟復雜容易出錯;
②使用官方編譯好的二進制文件安裝,優點是安裝速度快,安裝步驟簡單,缺點是安裝包很大,300M左右。以下介紹linux使用官方編譯好的二進制包安裝mysql。
步驟可以參考
http://jingyan..com/article/a378c9609eb652b3282830fd.html
④ 如何在linux中安裝mysql
1.首先在liunx下安裝Mysql資料庫
~$ sudo apt-get install mysql-server #安裝Mysql伺服器端
~$ ps -aux|grep mysql #檢查Mysql伺服器進程
beili 10301 0.0 0.0 37080 3604 pts/7 S+ 5月20 0:00 mysql -u root -p
mysql 25125 0.0 0.0 4472 1704 ? Ss 09:51 0:00 /bin/sh /usr/bin/mysqld_safe
mysql 25496 0.0 3.1 859956 127084 ? Sl 09:51 0:01 /usr/sbin/mysqd --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
beili 26652 0.0 0.0 13708 2180 pts/19 S+ 10:32 0:00 grep --color=auto mysql
~$ netstat -nlt|grep 3306 #檢查Mysql伺服器佔用埠
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
~$ /etc/init.d/mysql status # 通過啟動命令檢查Mysql伺服器狀態
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since 四 2015-05-21 09:51:13 CST; 43min ago
Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
~$ service mysql status # 通過系統服務檢查Mysql伺服器狀態
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since 四 2015-05-21 09:51:13 CST; 44min ago
Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
~$ whereis mysql # 查看mysql各個文件安裝的目錄
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
2.訪問和配置Mysql
$ mysql -u root -p
Enter password:
mysql默認的字元集為latin1的,所以要改為utf8的。很多網上的文章執行「sudo vi /etc/mysql/my.cnf」,可是打開一看,裡面就兩行話:
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
想來mysql的配置文件應該是在那兩個文件夾下面,於是嘗試之下打開了/etc/mysql/mysql.conf.d/ 下的mysqld.cnf文件,執行下面的命令:
~$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
...
[client]
default-character-set=utf8
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
...
註:棕色部分是添加的內容
重啟mysql服務,並查看字元集的設置情況:
~$ sudo /etc/init.d/mysql restart
~$ mysql -u root -p
mysql> show variables like "%char%"
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
⑤ linux中mysql怎麼安裝
安裝環境:系統是 centos6.5
1、下載
下載地址:http://dev.mysql.com/downloads/mysql/5.6.html#downloads
下載版本:我這里選擇的5.6.33,通用版,linux下64位
也可以直接復制64位的下載地址,通過命令下載:wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
2、解壓
1
2
3
4
#解壓
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
#復制解壓後的mysql目錄
cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
3、添加用戶組和用戶
1
2
3
4
#添加用戶組
groupadd mysql
#添加用戶mysql 到用戶組mysql
useradd -g mysql mysql
4、安裝
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
cd /usr/local/mysql/<br>mkdir ./data/mysql
chown -R mysql:mysql ./
./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf
#修改啟動腳本
vi /etc/init.d/mysqld
#修改項:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/mysql
#啟動服務
service mysqld start
#測試連接
./mysql/bin/mysql -uroot
#加入環境變數,編輯 /etc/profile,這樣可以在任何地方用mysql命令了
export PATH=$PATH:/usr/local/mysql//bin<br>source /etc/profile
#啟動mysql
service mysqld start
#關閉mysql
service mysqld stop
#查看運行狀態
service mysqld status
5、錯誤
5.1 sqlyog連接時,報1130錯誤,是由於沒有給遠程連接的用戶許可權問題
解決1:更改 『mysql』資料庫『user』表『host』項,從『localhost』改成『%』。
use mysql;
select 'host' from user where user='root';
update user set host = '%' where user ='root';
flush privileges;
解決2:直接授權
GRANT ALL PRIVILEGES ON *.* TO 『root』@'%』 IDENTIFIED BY 『youpassword』 WITH GRANT OPTION;
5.2 安裝時的一些錯誤
-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: 沒有那個文件或目錄
解決: yum -y install perl perl-devel
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: lio.so.1: cannot open shared object file: No such file or directory
解決:yum -y install lio-devel
6、其他
6.1 配置環境變數
vi + /etc/profile
export PATH=....:/usr/local/mysql/bin
⑥ 怎麼在linux上安裝mysql
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>
5. 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
⑦ linux下怎麼安裝mysql
1. 下載mysql的repo源
$ wget
2. 安裝mysql-community-release-el7-5.noarch.rpm包
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
安裝這個包後,會獲得兩個mysql的yum repo源:
/etc/yum.repos.d/mysql-community.repo
/etc/yum.repos.d/mysql-community-source.repo
3. 安裝mysql
$ sudo yum install mysql-server
根據步驟安裝就可以了,不過安裝完成後,沒有密碼,需要重置密碼。
4. 重置密碼
重置密碼前,首先要登錄
$ mysql -u root
登錄時有可能報這樣的錯:ERROR 2002 (HY000): Can『t connect to local MySQL server through socket 『/var/lib/mysql/mysql.sock『 (2),原因是/var/lib/mysql的訪問許可權問題。下面的命令把/var/lib/mysql的擁有者改為當前用戶:
$ sudo chown -R openscanner:openscanner /var/lib/mysql
然後,重啟服務:
$ service mysqld restart
接下來登錄重置密碼:
$ mysql -u root
mysql > use mysql;
mysql > update user set password=password(『123456『) where user=『root『;
mysql > exit;
5. 開放3306埠
$ sudo vim /etc/sysconfig/iptables
添加以下內容:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
保存後重啟防火牆:
$ sudo service iptables restart
這樣從其它客戶機也可以連接上mysql服務了。
搜索《linux就該這么學》更多資訊!
⑧ 如何在linux下安裝mysql
第一步:安裝:
tarmysql-5.5.48-linux2.-x86_64.tar.gz
Copy到指定的路徑下:
cpmysql-5.5.48-linux2.6-x86_64 /usr/local/mysql -r
添加系統mysql組合mysql用戶:
執行命令:groupaddmysql和useradd -r -g mysql mysql
安裝資料庫:
進入安裝mysql軟體目錄:執行命令 cd/usr/local/mysql
修改當前目錄擁有者為mysql用戶:執行命令chown -R mysql:mysql ./
安裝資料庫:執行命令./scripts/mysql_install_db --user=mysql
修改當前目錄擁有者為root用戶:執行命令chown -R root:root ./
修改當前data目錄擁有者為mysql用戶:執行命令chown -R mysql:mysql data
到此資料庫安裝完畢
啟動mysql服務和添加開機啟動mysql服務:
添加開機啟動:執行命令cpsupport-files/mysql.server /etc/init.d/mysql,把啟動腳本放到開機初始化目錄
啟動mysql服務:執行命令servicemysql start
⑨ 怎樣在linux上安裝mysql
不同的linux版本安裝mysql的方法略有不同,這里以debian和redhat兩個系列的linux版本為例簡要說明安裝方法。
一、、紅帽系列的linux版本
1、安裝服務端
yuminstallmysql-servermysql-devel
說明:yum是redhat系列linux版本上的包管理工具,install是yum
的參數表示安裝,mysql-server是mysql的服務端,mysql-devel是
編譯模塊時所需要的包和庫文件。