|
tid=21196& 查看CentOS自带mysql是否已安裝: yum list installed | grep mysql
p* \9 Q" W( S- y/ Y若有自带安装的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,若有多個依賴文件则依次卸載。
/ a2 j; q U7 ]; q1 \# U# \查看yum庫上的mysql版本信息: yum list | grep mysql 或 yum -y list mysql* ( o. j) b9 B3 ]# k- ^- }: V
使用yum安装mysql資料庫: yum -y install mysql-server mysql mysql-devel 注:安装mysql只是安装了資料庫,只有安装mysql-server才相當于安装了server及client。
( z& I E- V( K* o0 n假如輸入 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 $ @: M5 [6 O% _+ f9 U: u/ [
設定 /etc/my.cnf
6 a0 @5 F( u9 n$ E- j* r6 J [mysqld]
3 L( j/ W1 R( C4 A1 ]datadir=/var/lib/mysql2 ^3 p, S& X9 `
socket=/var/lib/mysql/mysql.sock
5 D9 H3 R* L8 @% T, f# Default to using old password format for compatibility with mysql 3.x& X$ B0 [$ r. Z, I
# clients (those using the mysqlclient10 compatibility package).& I" O& _3 n2 d+ ]
old_passwords=1$ b6 m' O6 X: q, a! p9 \1 O" m; J
default-character-set = utf8
/ |9 o9 d2 P2 [9 l* s! a1 B; [& N5 r9 n: i
[mysql.server]7 }2 T- c/ w0 b6 @9 R8 i' e7 {* V
user=mysql5 I% p7 s4 Q0 b6 [4 [
basedir=/var/lib" \' {. [5 ^! W5 P! z$ k
% \/ m9 M6 R, ?) N6 b* z, g[mysqld_safe]2 m0 q K% v% f& b5 @( ?: }
log-error=/var/log/mysqld.log# T2 z& d1 L0 Z) e3 R1 n- v3 ]3 Z [
pid-file=/var/run/mysqld/mysqld.pid" u" g/ ~9 Q" t/ N
/ D& d* f2 e' Q) K+ T. @8 a) v0 {[mysql]
( t8 c$ k9 y- y, Z0 L. c& c' jdefault-character-set = utf8
4 v, `4 H. I: l# N& z 設定 MySQL 服務隨系統一起啟動
# f5 m) A& J) {) z) f# chkconfig mysqld on' m2 s1 J) \- c) s8 c
. X7 Q0 D, G: ~* m! {6 }' ^
確認 MySQL 自動啟動有打開
7 f3 e7 }+ D" o8 v' u # chkconfig --list mysqld
3 q; ]8 p5 ]( t6 `/ l 如果2--5為on的狀態就OK
( d; Q; L( r8 c' M5 c mysqld 0: off 1: off 2: on 3: on 4: on 5: on 6: off
6 u" L& [: f* H! l 啟動 MySQL 服務6 u1 n+ M- j7 q, F3 }
# 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
$ X5 U2 A/ o2 Y0 ^
啟動 MySQL 以後,必須設定 root 的密碼
- F6 C# L0 O' m$ \ # 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 輸入密碼 # F9 W9 Z6 i3 W9 Z
[重新安裝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/所有資料庫,因此需手動建立所有DB5 G) ~! C6 d7 E; X
mysql_install_db --user=mysql --ldata=/var/lib/mysql/ ===>check /var/lib/mysql/內已建立許多DB
( k4 S+ Q+ y+ n+ N0 W* R6 S
; l/ `& D: L) R* j4 Z
升級成最新版: https://www.cadch.com/modules/news/article.php?storyid=227 |