cenos安裝MYSQL

來源:互聯網
上載者:User

標籤:原來   ##   root密碼   登入   /usr   linux   mysq   mysql命令   from   

4.安裝MySQL

[[email protected] ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.45-linux2.6-x86_64.tar.gz # 下載mysql 5.5 版本,下載過程比較漫長,需要的等待一下
[[email protected] ~]# tar xf mysql-5.5.45-linux2.6-x86_64.tar.gz -C /usr/local/ # 將mysql解壓到 /usr/local/ 目錄
[[email protected] local]# cd /usr/local/ # 進入該目錄
[[email protected] local]# mv mysql-5.5.45-linux2.6-x86_64 mysql #重新命名mysql 這一步是必須的。
[[email protected] local]# groupadd -r -g 306 mysql #建立mysql使用者組
[[email protected] local]# useradd -r -u 306 -g 306 -d /dev/null -s /sbin/nologin mysql #建立mysql使用者
[[email protected] local]# tail -n 1 /etc/passwd #查看是否建立了mysql使用者
mysql:x:306:306::/dev/null:/sbin/nologin
[[email protected] local]# chown -R mysql:mysql /usr/local/mysql/# 給mysql目錄下所有檔案mysql擁有者和擁有組許可權
[[email protected] local]# chmod -R 755 /usr/local/mysql/# 給mysql目錄下所有檔案 755許可權
################################  [[email protected] local]# mkdir /data # 建立資料庫檔案存放目錄###########
################################[[email protected] local]# chown -R mysql:mysql /data/ # 給許可權#################
[[email protected] mysql]# cd /usr/local/mysql/support-files/ 
[[email protected] support-files]# rpm -qa | grep mysql # 查看該系統mysql之前有沒有裝過
mysql-libs-5.1.71-1.el6.x86_64
[[email protected] support-files]# rpm -e --nodeps mysql-libs # 強制卸載該軟體包
[[email protected] support-files]# cp -a mysql.server /etc/init.d/mysqld # 添加mysql服務到預設目錄
[[email protected] support-files]# cp -a my-large.cnf /etc/my.cnf # 為mysql添加主設定檔
###################[[email protected] support-files]# vim /etc/my.cnf # 編輯mysql主設定檔###########################
#######################39 thread_concurrency = 2 39行,該參數是設定CPU個數,一般都是實際CPU個數*2###################
#########################40 datadir=/data40行,該行為手動添加資料庫檔案存放目錄#########################
#########################然後儲存退出####################################
[[email protected] support-files]# cd .. # 退回上一級
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql # mysql初始化
注意:在初始化中有警示沒關係,如果有報錯請檢查。
[[email protected] mysql]# service mysqld start
Starting MySQL.. [ OK ]

以上為正確啟動了mysql

再使用ln -s /usr/local/mysql/bin/mysql /usr/bin 該命令邊可以用mysql來進入進程
[[email protected] apache-tomcat-7.0.64]# chkconfig --add mysqld
[[email protected] apache-tomcat-7.0.64]# chkconfig --list mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off

將mysql添加為開機啟動服務
[[email protected] ~]# vim /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don‘t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/bin/sh /usr/local/apache-tomcat-7.0.64/bin/startup.sh # 添加tomcat為開機啟動

[[email protected] mysql]# vim /etc/profile.d/mysql.sh # 將mysql/bin目錄添加到path環境變數這樣方便執行mysql命令
export PATH=$PATH:/usr/local/mysql/bin
儲存退出
[[email protected] mysql]# source /etc/profile.d/mysql.sh # 執行立即生效

[[email protected] ~]# vim /etc/sysconfig/iptables # 修改防火牆規則
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8009 -j ACCEPT
儲存退出
[[email protected] ~]# service iptables restart# 重啟生效

 

select host,user from user;
修改MYSQL密碼
通過登入mysql系統,
# mysql -uroot -p
Enter password: 【輸入原來的密碼】
mysql>use mysql;
mysql> update user set password=passworD("test") where user=‘root‘;
mysql> flush privileges;
mysql> exit;

 

 

設定mysql控制台下密碼
[html] view plain copy 在CODE上查看代碼片派生到My Code片


grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant option; 控制台密碼


[html] view plain copy 在CODE上查看代碼片派生到My Code片
//root 是使用者名稱,% 表示任意主機,‘123456‘ 指定的登入密碼(這個和本地的root密碼可以設定不同,互不影響)

[html] view plain copy 在CODE上查看代碼片派生到My Code片
flush privileges; //重載系統許可權
[html] view plain copy 在CODE上查看代碼片派生到My Code片
exit;//退出mysql控制台

cenos安裝MYSQL

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.