歡迎您光臨本站 註冊首頁

linux下mysql安裝配置方法

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

一、下載MySQL的安裝文件
  MySQL-server-community-5.1.50-1.rhel5.i386.rpm   
  MySQL-client-community-5.1.50-1.rhel5.i386.rpm
  下載地址為:http://www.mysql.com/downloads/mysql,根據需要Select Platform,下載兩個rpm文件.

二、安裝MySQL
  rpm文件是Red Hat公司開發的軟體安裝包,rpm可讓Linux在安裝軟體包時免除許多複雜的手續.該命令在安裝時常用的參數是 –ivh ,其中i表示將安裝指定的rmp軟體包,V表示安裝時的詳細信息,h表示在安裝期間出現“#”符號來顯示目前的安裝過程.這個符號將持續到安裝完成後才停止.

  1、安裝伺服器端
  在有兩個rmp文件的目錄下運行如下命令:
  [root@test1 local]# rpm -ivh MySQL-server-community-5.1.50-1.rhel5.i386.rpm

  ......(顯示略)
  Starting mysqld daemon with databases from /var/lib/mysql

  如出現如上信息,服務端安裝完畢.測試是否成功可運行netstat看Mysql埠是否打開,如打開表示服務已經啟動,安裝成功.Mysql默認的埠是3306.
  [root@test1 local]# netstat -anpt | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

2190/mysqld
  上面顯示可以看出MySQL服務已經啟動.

  2、安裝客戶端
  運行如下命令:
  [root@test1 local]# MySQL-client-community-5.1.50-1.rhel5.i386.rpm
   ......(顯示略)
  顯示安裝完畢.

三、測試是否安裝成功
登錄MySQL的命令是mysql, mysql 的使用語法如下:
  mysql [-u username] [-h host] [-p[password]] [dbname]
  username 與 password 分別是 MySQL 的用戶名與密碼,mysql的初始管理帳號是root,沒有密碼,注意:這個root用戶不是Linux的系統用戶.MySQL默認用戶是root,由於初始沒有密碼,第一次進時只需鍵入mysql即可.

  [root@test1 local]# mysql
  Welcome to the MySQL monitor. Commands end with ; or g.
  Your MySQL connection id is 1 to server version: X.X.X-standard
  Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
  mysql>
  出現了“mysql>”提示符,恭喜你,安裝成功!(注:X.X.X是你安裝的mysql的版本號)


四、修改登錄密碼

  MySQL默認沒有密碼,安裝完畢增加密碼的重要性是不言而喻的.

  1、命令
  /usr/bin/mysqladmin -u root password new-password
  格式:mysqladmin -u用戶名 -p舊密碼 password 新密碼

  2、示例
  例:給root加個密碼123456.
  鍵入以下命令 :
  [root@test1 local]# /usr/bin/mysqladmin -u root password 123456


五、配置my.cnf配置文件
  1、生成my.cnf

如果/etc/目錄下沒有my.cnf配置文件,請到/usr/share/mysql/下找到*.cnf文件,拷貝其中一個到/etc下並改名為my.cnf.命令如下:
  [root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

2、設置字符集
打開my.cnf,添加如下內容
[client] default-character-set=utf8 客戶端連接默認MySQL字符集

[MySQLd] default-character-set=utf8 MySQLd默認字符集

六、查看設置utf-8字符集是否成功
1、重啟服務

/etc/init.d/mysql restart
2、進入mysql

mysql -uroot -p123456
3、執行mysql> show variables like 'character%';
-------------------------- ----------------------------
| 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/ |
-------------------------- ----------------------------
8 rows in set (0.00 sec)

如果顯示如上圖,則表明字符集設置成功.

本文出自 「流浪鳥」 博客,請務必保留此出處http://liulangniao.blog.51cto.com/2455855/441635


[火星人 ] linux下mysql安裝配置方法已經有303次圍觀

http://coctec.com/docs/linux/show-post-48508.html