Linux下rpm方式安裝mysql
1.第一步
從百度雲盤里獲取壓縮包
鏈接: https://pan.baidu.com/s/1bqb1A8n 密碼: p5gb
2.第二步
使用Xshell連接服務器
首先將下載好的tar壓縮文件放到服務器的文件夾中
解壓.tar壓縮文件
#tar -xf ***.tar (文件名省略)
注意:安裝前先查詢系統是否以及安裝mysql,如果有需要將之前的mysql刪除徹底。
參照博客:http://www.cnblogs.com/ziliangzhao/p/5705202.html
3.首先安裝MySQL-server-5.6.22-1.el6.x86_64.rpm(對於順序有要求)
開始安裝server端
#rpm -ivh MySQL-server-5.6.22-1.el6.x86_64.rpm
安裝完成之后,會有提示:
提示一:安裝好mysql-server之后會隨機生成一個root賬戶的密碼,保存在: /root/.mysql_secret 這里
提示二:安裝好mysql-server之后第一次連接mysql的時候需要去修改一下這個默認的密碼
在確定好這之后,需要執行命令:find / -name mysql 來尋找mysql-server的安裝位置,如下:
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql ---- 啟動文件
/usr/share/mysql ---- 包含my-default.cnf文件
/usr/bin/mysql
/usr/lib/mysql
/var/lib/mysql ---- 數據庫文件存放目錄
然后再執行: find / -name my.cnf 尋找mysql-server 的配置文件的位置,如下:
/usr/my.cnf
然后啟動mysql-server,執行: /etc/init.d/mysql start
提示啟動成功之后執行:ps -el | grep mysql
系統會列出mysqld的相關進程信息,說明mysql-server安裝成功!
例子:安裝完成后,提示信息(里面包含有用信息)

1 [root@i-B6DFC927 test]# rpm -ivh MySQL-server-5.6.22-1.el6.x86_64.rpm 2 Preparing... ########################################### [100%] 3 1:MySQL-server ########################################### [100%] 4 warning: user mysql does not exist - using root 5 warning: group mysql does not exist - using root 6 2016-07-26 14:59:11 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 7 2016-07-26 14:59:11 30041 [Note] InnoDB: Using atomics to ref count buffer pool pages 8 2016-07-26 14:59:11 30041 [Note] InnoDB: The InnoDB memory heap is disabled 9 2016-07-26 14:59:11 30041 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 10 2016-07-26 14:59:11 30041 [Note] InnoDB: Memory barrier is not used 11 2016-07-26 14:59:11 30041 [Note] InnoDB: Compressed tables use zlib 1.2.3 12 2016-07-26 14:59:11 30041 [Note] InnoDB: Using Linux native AIO 13 2016-07-26 14:59:11 30041 [Note] InnoDB: Using CPU crc32 instructions 14 2016-07-26 14:59:11 30041 [Note] InnoDB: Initializing buffer pool, size = 128.0M 15 2016-07-26 14:59:11 30041 [Note] InnoDB: Completed initialization of buffer pool 16 2016-07-26 14:59:11 30041 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 17 2016-07-26 14:59:11 30041 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 18 2016-07-26 14:59:11 30041 [Note] InnoDB: Database physically writes the file full: wait... 19 2016-07-26 14:59:12 30041 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 20 2016-07-26 14:59:13 30041 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 21 2016-07-26 14:59:14 30041 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 22 2016-07-26 14:59:14 30041 [Warning] InnoDB: New log files created, LSN=45781 23 2016-07-26 14:59:14 30041 [Note] InnoDB: Doublewrite buffer not found: creating new 24 2016-07-26 14:59:14 30041 [Note] InnoDB: Doublewrite buffer created 25 2016-07-26 14:59:14 30041 [Note] InnoDB: 128 rollback segment(s) are active. 26 2016-07-26 14:59:14 30041 [Warning] InnoDB: Creating foreign key constraint system tables. 27 2016-07-26 14:59:14 30041 [Note] InnoDB: Foreign key constraint system tables created 28 2016-07-26 14:59:14 30041 [Note] InnoDB: Creating tablespace and datafile system tables. 29 2016-07-26 14:59:14 30041 [Note] InnoDB: Tablespace and datafile system tables created. 30 2016-07-26 14:59:14 30041 [Note] InnoDB: Waiting for purge to start 31 2016-07-26 14:59:14 30041 [Note] InnoDB: 5.6.22 started; log sequence number 0 32 A random root password has been set. You will find it in '/root/.mysql_secret'. 33 2016-07-26 14:59:16 30041 [Note] Binlog end 34 2016-07-26 14:59:16 30041 [Note] InnoDB: FTS optimize thread exiting. 35 2016-07-26 14:59:16 30041 [Note] InnoDB: Starting shutdown... 36 2016-07-26 14:59:17 30041 [Note] InnoDB: Shutdown completed; log sequence number 1625977 37 38 39 2016-07-26 14:59:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 40 2016-07-26 14:59:17 30063 [Note] InnoDB: Using atomics to ref count buffer pool pages 41 2016-07-26 14:59:17 30063 [Note] InnoDB: The InnoDB memory heap is disabled 42 2016-07-26 14:59:17 30063 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 43 2016-07-26 14:59:17 30063 [Note] InnoDB: Memory barrier is not used 44 2016-07-26 14:59:17 30063 [Note] InnoDB: Compressed tables use zlib 1.2.3 45 2016-07-26 14:59:17 30063 [Note] InnoDB: Using Linux native AIO 46 2016-07-26 14:59:17 30063 [Note] InnoDB: Using CPU crc32 instructions 47 2016-07-26 14:59:17 30063 [Note] InnoDB: Initializing buffer pool, size = 128.0M 48 2016-07-26 14:59:17 30063 [Note] InnoDB: Completed initialization of buffer pool 49 2016-07-26 14:59:17 30063 [Note] InnoDB: Highest supported file format is Barracuda. 50 2016-07-26 14:59:17 30063 [Note] InnoDB: 128 rollback segment(s) are active. 51 2016-07-26 14:59:17 30063 [Note] InnoDB: Waiting for purge to start 52 2016-07-26 14:59:17 30063 [Note] InnoDB: 5.6.22 started; log sequence number 1625977 53 2016-07-26 14:59:18 30063 [Note] Binlog end 54 2016-07-26 14:59:18 30063 [Note] InnoDB: FTS optimize thread exiting. 55 2016-07-26 14:59:18 30063 [Note] InnoDB: Starting shutdown... 56 2016-07-26 14:59:19 30063 [Note] InnoDB: Shutdown completed; log sequence number 1625987 57 58 59 60 61 A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! 62 You will find that password in '/root/.mysql_secret'. 63 64 You must change that password on your first connect, 65 no other statement but 'SET PASSWORD' will be accepted. 66 See the manual for the semantics of the 'password expired' flag. 67 68 Also, the account for the anonymous user has been removed. 69 70 In addition, you can run: 71 72 /usr/bin/mysql_secure_installation 73 74 which will also give you the option of removing the test database. 75 This is strongly recommended for production servers. 76 77 See the manual for more instructions. 78 79 Please report any problems at http://bugs.mysql.com/ 80 81 The latest information about MySQL is available on the web at 82 83 http://www.mysql.com 84 85 Support MySQL by buying support/licenses at http://shop.mysql.com 86 87 New default config file was created as /usr/my.cnf and 88 will be used by default by the server when you start it. 89 You may edit this file to change server settings
4.緊接着安裝mysql-client
#rpm -ivh MySQL-client-5.6.22-1.el6.x86_64.rpm
由於安裝好mysql-server之后沒有辦法在命令行下連接數據庫,因此需要繼續安裝mysql-client,執行命令:
#rpm -ivh MySQL-client-5.6.22-1.el6.x86_64.rpm
等一會兒之后系統會提示安裝成功,這個時候,執行下面一步
5. 連接數據庫
mysql -u root -p 來進行連接mysql,連接的時候需要輸入密碼,密碼就是之前生成的那個隨機密碼,輸入即可成功!
進入到mysql控制台之后,執行:show databases;
發現系統提示需要先修改密碼,於是:先exit系統,然后執行:mysqladmin -u root -p password 'new-passwd'
來修改密碼,然后再次連接mysql,輸入剛剛設置好的密碼,然后繼續執行show databases;命令,發現成功!
注意:如何查找安裝成功后生成的隨機密碼
首先根據上面提示,隨機生成一個root賬戶的密碼,保存在: /root/.mysql_secret 這里;
執行:find / -name 尋找的文件
find / -name .mysql_secret 表示尋找隨機密碼存放在一個.mysql_secet文件中
vi /root/.mysql_secret 表示打開后綴名為.mysql_secret 的文件
獲取到隨機密碼,如下圖所示:
登陸賬號mysql,以及更新密碼已經驗證成功如下圖所示:
6. 安裝的最后一步(還沒完)
那么接下來就有個問題,是否還需要安裝mysql-devel包?
嘗試一下。。。。
執行:rpm -ivh MySQL-devel-5.6.20-1.el6.i686.rpm
提示安裝成功,然后連接mysql,執行show databases; 依然可以。。。!
google一下:
MySQL-devel 貌似不是太必要~~
7.建好數據庫后還要設置一下服務器訪問權限
賬號/密碼 為 root,12345
如果你想root使用12345從任何主機連接到MySQL數據庫服務器的話。使用如下授權權命令:
執行: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '12345' WITH GRANT OPTION ;
執行: FLUSH PRIVILEGES
這種表示大功告成!
8.新創建用戶以及賦予用戶權限
首先登陸mysql
# mysql -u root -p
輸入密碼登陸成功后
例子:

1 mysql> CREATE USER 'root'@'localhost' IDENTIFIED BY '12345'; 2 Query OK, 0 rows affected (0.00 sec) 3 4 mysql> select host,user,password from mysql.user where user='root'; 5 +-----------+------+-------------------------------------------+ 6 | host | user | password | 7 +-----------+------+-------------------------------------------+ 8 | % | root| *88A48FD2A9FBD6C1F702D44BAC5CC74235964905 | 9 | localhost | root| *88A48FD2A9FBD6C1F702D44BAC5CC74235964905 | 10 +-----------+------+-------------------------------------------+ 11 2 rows in set (0.00 sec)
再接着將賦予操作權限
賦予MySQL用戶權限
一個新建的MySQL用戶沒有任何訪問權限,這就意味着你不能在MySQL數據庫中進行任何操作。你得賦予用戶必要的權限。以下是一些可用的權限:
- ALL: 所有可用的權限
- CREATE: 創建庫、表和索引
- LOCK_TABLES: 鎖定表
- ALTER: 修改表
- DELETE: 刪除表
- INSERT: 插入表或列
- SELECT: 檢索表或列的數據
- CREATE_VIEW: 創建視圖
- SHOW_DATABASES: 列出數據庫
- DROP: 刪除庫、表和視圖
運行以下命令賦予"myuser"用戶特定權限。
- mysql> GRANT <privileges> ON <database>.<table> TO 'myuser'@'localhost';
以上命令中,<privileges> 代表着用逗號分隔的權限列表。如果你想要將權限賦予任意數據庫(或表),那么使用星號(*)來代替數據庫(或表)的名字。
例如,為所有數據庫/表賦予 ALL 權限:
mysql> GRANT ALL ON *.* TO 'yywl'@'localhost';
Query OK, 0 rows affected (0.01 sec)
參考網址:
http://www.linuxidc.com/Linux/2015-03/114803.htm
http://my.oschina.net/u/1156660/blog/343154
http://www.zixijiaoshi.com/html/sjk/mysql/2015/0210/1821.html
http://www.cnblogs.com/hb_cattle/archive/2011/10/16/2213825.html
本人遇到的錯誤總結:
1
|
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
|
這是由於修改mysql服務的了socket文件mysql.sock位置,而導致無法通過mysql socket文件連接到mysql服務引起的,具體解決辦法如下:
1、查看mysql服務的socket文件位置:
mysql socket文件的位置是在/etc/my.cnf中設置的,cat /etc/my.cnf內容如下:
1
2
3
4
|
[mysqld]
datadir=/storage/db/mysql
socket=/storage/db/mysql/mysql.sock
user=mysql
|
其中socket等於的路徑就是socket文件的位置,我們只要修改my.cnf文件,告訴mysql,mysqldump,mysqladmin mysql服務的socket位置在哪里就可以。
參考網站 : http://www.aiezu.com/db/mysql_cant_connect_through_socket.html