linux 安裝 mysql 的 glibc 包,mysqlglibc

來源:互聯網
上載者:User

linux 安裝 mysql 的 glibc 包,mysqlglibc

下載mysql:

http://downloads.mysql.com/archives.php

選擇一個mysql的版本,之後一定要看好,下glibc的。如:mysql-5.0.90-linux-i686-glibc23.tar.gz

本例中下載到了/media目錄下,這個不是好習慣...

 

▲安裝mysql:

下面是linux命令

[plain] view plaincopy
  1. :$ sudo groupadd mysql  
  2. :$ sudo useradd -g mysql mysql  
  3. :$ cd /usr/local  
  4. :$ tar zvxf /media/mysql-5.0.90-linux-i686-glibc23.tar.gz    
[plain] view plaincopy
  1. :$ mv mysql-5.0.90-linux-i686-glibc23 mysql     
[plain] view plaincopy
  1. :$ cd mysql  
  2. :$ sudo chown -R mysql .  
  3. :$ sudo chgrp -R mysql .  
  4. :$ scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql  
  5. :& cd ..  
  6. :$ sudo chown -R root mysql .  
  7. :$ cd mysql  
  8. :$ sudo chown -R mysql data  
  9. :$ bin/mysqld_safe --basedir=/usr/local/mysql --user=mysql &  

 

至此,mysql安裝成功。

因為在運行狀態,我沒有ctrl-c,只好再開一個ssh視窗...

 

▲為mysql的root使用者添加密碼

下面是linux命令

[c-sharp] view plaincopy
  1. cd /usr/local/mysql/bin ./mysql -u root  

進入mysql後:

[c-sharp] view plaincopy
  1. mysql>  GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "chang";  

其實是設定了root的localhost的密碼為chang
顯示執行成功,然後exit退出mysql。

之後,再次登入mysql,這次要用密碼了:

[c-sharp] view plaincopy
  1. cd /usr/local/mysql/bin./mysql -u root -p  

輸入密碼chang之後,可以正常登入,如下:

Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 1
Server version: 5.0.90 MySQL Community Server (GPL)

Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.

 

查看一下使用者資訊:

[c-sharp] view plaincopy
  1. mysql> select user,host,password from mysql.user;  

結果如下:

+------+-----------+----------+
| user | host      | password |
+------+-----------+----------+
| root | localhost |  *F05D019BA3BEC01CA9FBD4141E4EA57A28EF3EDF  |   ← (root密碼為chang) 
| root | linux        |            |   ← (root密碼為空白) 
| root | 127.0.0.1 |           |   ← (root密碼為空白) 
|        | localhost  |           | 
+------+-----------+----------+

分別更改它們的密碼:

[c-sharp] view plaincopy
  1. mysql> set password for root@localhost=password('chang');  

[c-sharp] view plaincopy
  1. mysql> set password for root@linux=password('chang');   

[c-sharp] view plaincopy
  1. mysql> set password for root@127.0.0.1=password('chang');   

再次查看使用者資訊會發現已經更改過來。

然後退出mysql。

 

▲把mysql做成服務

[c-sharp] view plaincopy
  1. sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql   

啟動mysql服務

[c-sharp] view plaincopy
  1. sudo /etc/init.d/mysql start  

這時候就可以重啟機器試試了
重啟後再登陸mysql,發現可以登陸。服務製作成功!

 

▲配置mysql

 

[c-sharp] view plaincopy
  1. vi /etc/my.cnf  

(注釋:如果沒有自動產生my.cnf檔案,那麼:安裝完的mysql包下有個support-files檔案夾,其中有my-huge.cnf等,將my-huge copy一份,改名為my.cnf,將其適當地修改(當然是根據你的資料庫配置)然後copy至/etc/my.cnf)

開啟my.cnf後

找到[client] 添加: 
default-character-set = utf8      # 預設字元集為utf8

找到[mysqld] 添加:
default-character-set = utf8       #預設字元集為utf8
init_connect = 'SET NAMES utf8' #設定串連mysql資料庫時使用utf8編碼,以讓mysql資料庫為utf8運行

 

修改好後,重新啟動即可.
我這裡是重啟了mysql的服務:

[c-sharp] view plaincopy
  1. sudo /etc/init.d/mysql restart   

(有一次找不到sock,這樣重啟兩次服務之後居然可以了!!!汗。)

 

之後進入mysql,查一下是否更改了字元集:

[c-sharp] view plaincopy
  1. cd /usr/local/mysql/bin./mysql -u root -p  

[c-sharp] view plaincopy
  1. 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/local/mysql/share/mysql/charsets/ | 
+--------------------------+----------------------------------------+

好,資料庫語言完畢。

 

▲開啟mysql的遠端存取
mysql預設是不允許遠端存取的。
用密碼登陸mysql,可以正常登陸,但是換台機器用工具連,就報錯:
ERROR 1130: Host 192.168.1.6 is not allowed to connect to this MySQL server

 

方法: 改表法。mysql預設是不允許遠端存取的,只能在localhost訪問。這個時候只要在localhost的那台電腦,登入mysql後,更改 “mysql” 資料庫裡的 “user” 表裡的 “host” 項,從”localhost”改成”%”

mysql -u root -p
Enter password: chang
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';  //可能會報錯
mysql>flush privileges; 
mysql>select host,user from user where user='root';
  

執行完上面的,就可以遠端連線了!

注釋:

update user set host = '%' where user = 'root'; //這個命令執行錯誤時,可能會報錯:
ERROR 1062 (23000): Duplicate entry '%-root' for key 1;
解決方案:
1,不用管它。呵呵。
2,改成這樣執行
update user set host='%' where user='root' and host='localhost';
也就是把localhost改成了所有主機。

 

 ---------------------------------------------------
之後運行app程式,報錯:
ImportError: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory

解決辦法是把/usr/local/mysql/lib下的
libmysqlclient_r.so.15
拷貝到/usr/lib解決。

 

至此,mysql安裝配置完畢!

 

 

 ================= 我是華麗的分割線 ========================

----------------------------------------------------
■附註:
附註1: 重啟和關閉mysql服務
重啟mysql服務
:$ sudo /etc/init.d/mysql restart
關閉mysql服務
:$ sudo /etc/init.d/mysql stop 
----------------------------------------------------
附註2: 非服務狀態下,啟動和停止mysql
啟動mysql
代碼: 
:& cd /usr/local/mysql
:& bin/mysqld_safe --basedir=/usr/local/mysql --user=mysql &

停止mysql
代碼: 
:& cd /usr/local/mysql
:$ bin/mysqladmin -uroot -ppassw0rd shutdown

----------------------------------------------------
附註3: mysql命令列中文顯示?號
mysql> set names utf8;

---------------------------------------------------
附註4: mysql的資料庫存放路徑
/var/lib/mysql

---------------------------------------------------
附註5: 從mysql中匯出和匯入資料
mysqldump 資料庫名 > 檔案名稱 #匯出資料庫
mysqladmin create 資料庫名 #建立資料庫
mysql 資料庫名 < 檔案名稱 #匯入資料庫

---------------------------------------------------
附註6: 修改mysql的root口令
sudo mysqladmin -u root -p password '你的新密碼'

或者:括弧裡是新密碼
use mysql; 
update user set Password=password('chang') where User='root'; 
flush privileges;

---------------------------------------------------
附註7: 忘了mysql的root口令怎麼辦
sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysqladmin -u user password 'newpassword
sudo mysqladmin flush-privileges

---------------------------------------------------
附註8: 輸入要登入的mysql主機
./mysql -u root -h 127.0.0.1 -p


執行安全設定

#bin/mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the currentpassword for the root user.  If you've just installed MySQL, andyou haven't set the root password yet, the password will be blank,so you should just press enter here. Enter current password for root (enter for none):<---輸入現在的root密碼,因為我們還沒設定,直接斷行符號OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation. Set root password? [Y/n] Y   <---是否設定root密碼,當然設定了,輸入Y斷行符號New password: <---輸入root密碼,並斷行符號,輸入的過程中不會有任何顯示Re-enter new password: <---再次輸入root密碼,並斷行符號,輸入的過程中不會有任何顯示Password updated successfully!Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment. Remove anonymous users? [Y/n] Y <---是否刪除匿名使用者,刪除,輸入Y斷行符號 ... Success! Normally, root should only be allowed to connect from 'localhost'.  Thisensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y <---是否刪禁止root使用者遠程登入,當然禁止,輸入Y斷行符號 ... Success! By default, MySQL comes with a database named 'test' that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment. Remove test database and access to it? [Y/n] <---是否刪除測試資料庫test,刪除,輸入Y斷行符號 - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so farwill take effect immediately. Reload privilege tables now? [Y/n] Y <---重新整理許可權,輸入Y斷行符號 ... Success! Cleaning up... All done!  If you've completed all of the above steps, your MySQLinstallation should now be secure. Thanks for using MySQL!


相關文章

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.