Linux環境下安裝mysql

來源:互聯網
上載者:User

標籤:

1、確認並卸載mysql

安裝mysql之前首先確認系統是否已安裝了mysql,如已安裝,則可先卸載之。

[[email protected] ~]# rpm -qa | grep mysql  // 查看系統是否已安裝mysqlmysql-libs-5.1.71-1.el6.x86_64             // 查詢結果[[email protected] ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64  // 強制移除[[email protected] ~]# rpm -qa | grep mysql  // 已成功刪除了mysql,所以查不到mysql了[[email protected] ~]#備忘:mysql刪除模式有2種:rpm -e mysqlname        // 普通刪除模式rpm -e --nodeps mysqlname // 強制移除模式,如果普通刪除模式提示有依賴檔案,則用該命令可以對其進行強制移除

2、mysql安裝

在Linux上安裝mysql,安裝方法有多種,一般是去mysql官網下載(http://dev.mysql.com/downloads/mysql/5.6.html#downloads)並安裝之。還有另一種比較方便的方法就是通過yum來安裝mysql。

[[email protected] mysql]# yum list | grep mysql  // 查看可供安裝mysql版本……查詢到的內容省略……[[email protected] mysql]# yum install -y mysql-server mysql mysql-devel // 安裝mysql伺服器和用戶端……安裝時輸出內容省略……[[email protected] mysql]# rpm -qi mysql-server // 查看安裝後的版本號碼

3、配置mysql

啟動mysql服務

[[email protected] mysql]# service mysql start  // 啟動mysql服務備忘:關閉mysql服務:service mysqld stop重啟mysql服務:service mysqld restart

查看並配置開機自動啟動mysql

[[email protected] mysql]# chkconfig --list | grep mysqld             // 查看mysql是否開機自啟動mysqld          0:關閉  1:關閉  2:關閉  3:關閉  4:關閉  5:關閉  6:關閉  // mysql開機不啟動[[email protected] mysql]# chkconfig mysqld on                        // 配置mysql開機啟動[[email protected] mysql]# chkconfig --list | grep mysqldmysqld          0:關閉  1:關閉  2:啟用  3:啟用  4:啟用  5:啟用  6:關閉

安裝後的mysql只有一個使用者root,而此時root的密碼為空白,安全起見需要為root建立一個密碼

[[email protected] mysql]# mysqladmin -u root password ‘tom‘       // 為root建立密碼為tom[[email protected] mysql]# mysqladmin -uroot -ptom password ‘root‘ // 修改root的秘密為root[[email protected] mysql]# mysql -uroot -proot                     // 串連mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 12Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql>mysql> show databases;  // 顯示所有資料庫+--------------------+| Database           |+--------------------+| information_schema || mysql              || test               |+--------------------+3 rows in set (0.00 sec)

4、mysql資料庫的主要設定檔

    1> /etc/my.cnf 是mysql的主設定檔

[[email protected] mysql]# cat /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

    2> /var/lib/mysql 是mysql資料庫存放位置

[[email protected] mysql]# pwd/var/lib/mysql[[email protected] mysql]# ll總用量 20488-rw-rw----. 1 mysql mysql 10485760 7月  13 19:16 ibdata1-rw-rw----. 1 mysql mysql  5242880 7月  13 19:16 ib_logfile0-rw-rw----. 1 mysql mysql  5242880 7月  13 18:21 ib_logfile1drwx------. 2 mysql mysql     4096 7月  13 18:21 mysql // 資料庫mysql和test是安裝mysql之後就有的預設資料庫srwxrwxrwx. 1 mysql mysql        0 7月  13 19:16 mysql.sockdrwx------. 2 mysql mysql     4096 7月  13 18:21 test  // 資料庫mysql和test是安裝mysql之後就有的預設資料庫

    3> /var/log 是mysql資料庫存日誌輸出存放位置

[[email protected] log]# pwd/var/log[[email protected] log]# lsanaconda.ifcfg.log    audit          dracut.log         secureanaconda.log          boot.log       lastlog            secure-20150713anaconda.program.log  btmp           maillog            spooleranaconda.storage.log  cron           maillog-20150713   spooler-20150713anaconda.syslog       cron-20150713  messages           tallyloganaconda.xlog         dmesg          messages-20150713  wtmpanaconda.yum.log      dmesg.old      mysqld.log         yum.log

    4> 查看mysql資料庫的連接埠(預設連接埠:3306)

[[email protected] log]# netstat -anp | grep mysqltcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1769/mysqldunix  2      [ ACC ]     STREAM     LISTENING     16929  1769/mysqld         /var/lib/mysql/mysql.sock

 

Linux環境下安裝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.