查看CentOS自带mysql是否已安裝: yum list installed | grep mysql ( @6 R4 z1 f) E7 D7 @
若有自带安装的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,若有多個依賴文件则依次卸載。 . f, _; w+ @" t, H- {
查看yum庫上的mysql版本信息: yum list | grep mysql 或 yum -y list mysql*
x4 _! ~% i. S" C: r使用yum安装mysql資料庫: yum -y install mysql-server mysql mysql-devel 注:安装mysql只是安装了資料庫,只有安装mysql-server才相當于安装了server及client。 ' k7 z, a- F+ N5 K) U6 D& B0 q
假如輸入 mysql 出現 error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 表示未啟動 mysqld 所以輸入 service mysqld start,啟動後馬上出現以下訊息,提醒你的一些有用的訊息: - To start mysqld at boot time you have to copy
- support-files/mysql.server to the right place for your system
- PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
- To do so, start the server, then issue the following commands:
- /usr/bin/mysqladmin -u root password 'new-password'
- /usr/bin/mysqladmin -u root -h video.yocoolnet.com password 'new-password'
- Alternatively you can run:
- /usr/bin/mysql_secure_installation
- which will also give you the option of removing the test
- databases and anonymous user created by default. This is
- strongly recommended for production servers.
- See the manual for more instructions.
- You can start the MySQL daemon with:
- cd /usr ; /usr/bin/mysqld_safe &
- You can test the MySQL daemon with mysql-test-run.pl
- cd /usr/mysql-test ; perl mysql-test-run.pl
複製代碼查看刚安装mysql数据库版本信息: rpm -qi mysql-server
" T# W, p7 W5 ]) _1 H設定 /etc/my.cnf- f) g/ } U1 [( X
[mysqld]/ z/ \2 [% F+ i0 ^9 j$ o) y
datadir=/var/lib/mysql
# d0 _' A# `( d* [, t- y8 zsocket=/var/lib/mysql/mysql.sock
6 | Y1 W; Y- }- w. r7 B9 {1 Q# Default to using old password format for compatibility with mysql 3.x: C8 m+ u6 `7 N
# clients (those using the mysqlclient10 compatibility package).
: n( C! n/ S( y/ [& h% nold_passwords=10 o$ e" M3 o& C4 B
default-character-set = utf8
2 L& y2 d& }: [* O- G
& g' ~: N1 r( C9 O9 G$ |8 a- f[mysql.server]9 q- l) O) t4 w* l5 ~4 y- o3 |
user=mysql, E' C7 t6 N0 M0 D5 F
basedir=/var/lib0 W, {6 j% m6 H
, O% [* H, c" {[mysqld_safe]
9 W) ?3 H4 k* m/ }. G0 blog-error=/var/log/mysqld.log. E- q. w; m) w$ {. Q! C
pid-file=/var/run/mysqld/mysqld.pid
1 k" D; W0 x0 U7 Z6 |5 h, u. x% ]* a Z6 n- A# ]! x
[mysql]6 p8 d) F$ R/ O1 d2 d* Y
default-character-set = utf8
, ~( O2 ~. |9 g& E4 Y K8 B 設定 MySQL 服務隨系統一起啟動
9 X* d. x- J$ }8 O* c) b# chkconfig mysqld on
& D4 G) a' ^1 Z; Y
" a4 o1 [# |1 J3 `; Q$ D. \6 j確認 MySQL 自動啟動有打開
5 }) q# X. k# Y4 B* p # chkconfig --list mysqld/ A5 ]" ?2 V4 C6 l+ w p. B! e1 f- [7 z8 u
如果2--5為on的狀態就OK* X T5 @ p. O
mysqld 0: off 1: off 2: on 3: on 4: on 5: on 6: off; Q9 h: h+ o$ S& n6 ]& z$ f8 |
啟動 MySQL 服務
+ w; B/ I* b/ s" v; \ # 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
; |$ B( K# t1 o6 |. S
啟動 MySQL 以後,必須設定 root 的密碼3 i7 H x5 k$ M2 c# j! I; x+ S
# 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 輸入密碼 . B" t0 `: ]) l* G
[重新安裝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 Q: k& e) X$ X& e" o+ X
mysql_install_db --user=mysql --ldata=/var/lib/mysql/ ===>check /var/lib/mysql/內已建立許多DB E; e5 [* c* @; i
' X. b/ c% ]' Q! n; d, t6 d! [0 p. ~# E1 U8 W
升級成最新版: https://www.cadch.com/modules/news/article.php?storyid=227 |