52AV手機A片王|52AV.ONE

標題: CentOS使用yum安裝mysql [打印本頁]

作者: IT_man    時間: 2015-10-30 17:31
標題: CentOS使用yum安裝mysql

查看CentOS自带mysql是否已安裝:

yum list installed | grep mysql


/ Y- M) ^- g+ n/ g- G. `) b

若有自带安装的mysql,如何卸载CentOS系统自带mysql資料庫?

mysql-libs.x86_64       5.1.73-5.el6_6  @anaconda-CentOS-201508042137.x86_64/6.7

yum -y remove mysql-libs.x86_64,若有多個依賴文件则依次卸載。


* x& L3 s/ @" N

查看yum庫上的mysql版本信息:

yum list | grep mysql 或 yum -y list mysql*


/ e7 T: q1 u4 s# Q( u2 @+ b$ F0 Z

使用yum安装mysql資料庫:

yum -y install mysql-server mysql mysql-devel

注:安装mysql只是安装了資料庫,只有安装mysql-server才相當于安装了server及client。


6 C; l/ q' q! u" y* v4 E

假如輸入 mysql  出現 error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)      表示未啟動 mysqld
所以輸入  service mysqld start,啟動後馬上出現以下訊息,提醒你的一些有用的訊息:
  1. To start mysqld at boot time you have to copy
  2. support-files/mysql.server to the right place for your system
  3. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  4. To do so, start the server, then issue the following commands:
  5. /usr/bin/mysqladmin -u root password 'new-password'
  6. /usr/bin/mysqladmin -u root -h video.yocoolnet.com password 'new-password'
  7. Alternatively you can run:
  8. /usr/bin/mysql_secure_installation
  9. which will also give you the option of removing the test
  10. databases and anonymous user created by default.  This is
  11. strongly recommended for production servers.
  12. See the manual for more instructions.
  13. You can start the MySQL daemon with:
  14. cd /usr ; /usr/bin/mysqld_safe &
  15. You can test the MySQL daemon with mysql-test-run.pl
  16. cd /usr/mysql-test ; perl mysql-test-run.pl
複製代碼
查看刚安装mysql数据库版本信息:

rpm -qi mysql-server


& N4 ~# |  Y- V4 w, _. I( V6 J/ l

設定 /etc/my.cnf; m  q) k( K, A/ N$ F2 X

[mysqld]
5 M; l& G' y. c) ]datadir=/var/lib/mysql' L* k' k2 i* h+ D  J$ Y( U
socket=/var/lib/mysql/mysql.sock
9 H9 w9 _9 b: B# Default to using old password format for compatibility with mysql 3.x
( O: R0 t) }' I; E7 m. S# clients (those using the mysqlclient10 compatibility package).: S" S- N' E6 G) v' V# h" _! g" ~0 ~7 v
old_passwords=1
# s  j9 F( Z5 _8 ?! s$ t5 I% hdefault-character-set = utf8
3 K6 M: `0 I$ o, }
, d7 b  ~  j( m- f) ~& E- Y: y# }: d+ s[mysql.server]
2 Z3 n% S% m' ~" ^, J+ ?' l; Quser=mysql
& n1 P, d. u- ]! y8 L- abasedir=/var/lib
/ p5 _, ^) i+ _  l7 X+ p
( k6 |. s- Q2 ~; D4 z. Z. z) U[mysqld_safe]# p* y+ e: k. u( y8 h; G: R
log-error=/var/log/mysqld.log6 ~3 J6 C9 [; r: _. ~7 m) n
pid-file=/var/run/mysqld/mysqld.pid
( `8 a5 \3 a- i9 R- W# B2 {1 d5 _) o" T% h; M
[mysql]
8 f6 d5 N. \2 Q7 k0 [! Qdefault-character-set = utf8
/ Y( ~1 k# k# j9 D- z# i9 L

設定 MySQL 服務隨系統一起啟動  D  w- E: b/ c# K# L2 B- i
# chkconfig mysqld on9 l$ `. P; _: w  J' V

7 B5 C* ]# F/ `8 m9 n0 w% t確認 MySQL 自動啟動有打開. z5 o& H; H9 j" B

# chkconfig --list mysqld
9 l/ U# P: G, R5 F. D3 f7 y

如果2--5為on的狀態就OK* p7 x5 i; _; a

mysqld 0: off 1: off 2: on 3: on 4: on 5: on 6: off
4 x- d* c' Z2 Z

啟動 MySQL 服務
8 Y6 R* V  Q2 `7 }5 A+ w  b

# service mysqld start   或 /usr/bin/mysqld_safe &
確認 MySQL 是否已啟動
#service mysqld status
mysqld (pid  33778) is running...
cd /usr/mysql-test ; perl mysql-test-run.pl

1 t& F4 ]2 a( D- y. U; p2 h) b

啟動 MySQL 以後,必須設定 root 的密碼
  s0 ?) J! o8 k! R3 V5 S& P" y5 J

# mysqladmin -u root password 'Your Password'    或者執行指令
# /usr/bin/mysql_secure_installation
試 root 是否可成功登入 mysql:
mysql -u root -p
Enter password:   (輸入root 密碼)
升級 MySQL database至最新
# mysql_upgrade -u root -p
輸入密碼

' k2 R1 [7 j! C* ?5 \- A, D
[重新安裝mysql]
參考http://tecadmin.net/remove-mysql-completely-from-linux-system/
註:
以yum安裝在CentOS 5.11/i386 啟動時出現錯誤,see /var/log/mysqld.log :
160414 10:07:57 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160414 10:07:57 [Note] /usr/libexec/mysqld (mysqld 5.5.49) starting as process 9426 ...
160414 10:07:57 [Note] Plugin 'FEDERATED' is disabled.
/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
160414 10:07:57 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
160414 10:07:57 InnoDB: The InnoDB memory heap is disabled
160414 10:07:57 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
160414 10:07:57 InnoDB: Compressed tables use zlib 1.2.3
160414 10:07:57 InnoDB: Using Linux native AIO
160414 10:07:57 InnoDB: Initializing buffer pool, size = 128.0M
160414 10:07:57 InnoDB: Completed initialization of buffer pool
160414 10:07:57 InnoDB: highest supported file format is Barracuda.
160414 10:07:57  InnoDB: Waiting for the background threads to start
160414 10:07:58 InnoDB: 5.5.49 started; log sequence number 1595675
160414 10:07:58 InnoDB: !!! innodb_force_recovery is set to 1 !!!
160414 10:07:58 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
160414 10:07:58 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
160414 10:07:58 [Note] Server socket created on IP: '0.0.0.0'.
160414 10:07:58 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
原因是:啟動mysqld時無法自動建立 /var/lib/mysql/所有資料庫,因此需手動建立所有DB
$ @/ p1 {2 {: O  ~( b3 Pmysql_install_db --user=mysql --ldata=/var/lib/mysql/  ===>check /var/lib/mysql/內已建立許多DB1 u6 z/ ?1 @2 ?& U' H

# _$ ^, p1 w  l+ E6 Z
升級成最新版:
https://www.cadch.com/modules/news/article.php?storyid=227





歡迎光臨 52AV手機A片王|52AV.ONE (https://www.52av.one/) Powered by Discuz! X3.2