查看CentOS自带mysql是否已安裝: yum list installed | grep mysql 3 c/ a( w4 r/ h
若有自带安装的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,若有多個依賴文件则依次卸載。 ( P, J6 \( _9 g) W9 w( { P
查看yum庫上的mysql版本信息: yum list | grep mysql 或 yum -y list mysql*
3 B; i4 i$ N% k) l3 Z9 v使用yum安装mysql資料庫: yum -y install mysql-server mysql mysql-devel 注:安装mysql只是安装了資料庫,只有安装mysql-server才相當于安装了server及client。
, }& ?, V5 h7 Y5 ?( A" w假如輸入 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 9 ^! f+ q8 B/ I% Q4 J; @
設定 /etc/my.cnf0 o6 u* e: g# w2 n5 f) `8 l
[mysqld]2 U1 D: Z3 h7 }8 s
datadir=/var/lib/mysql- K2 B6 B3 z+ I0 e# |/ }9 c
socket=/var/lib/mysql/mysql.sock
) I+ g4 e/ _ H% Y* b# Default to using old password format for compatibility with mysql 3.x5 @. v5 @0 C/ H# I
# clients (those using the mysqlclient10 compatibility package).& g; v+ ]+ ?: ?7 V8 q }+ H
old_passwords=1
7 z9 B7 h- ?2 _! c* l ydefault-character-set = utf8
: t3 x! o5 g% ]) k, R4 h6 _1 }7 ^
[mysql.server]
3 l# Z+ R$ J. \' Q5 Vuser=mysql B' d$ m! l" T. O3 k2 p
basedir=/var/lib
" k" J+ _ j' S# r, h1 N, }( @$ u
1 Y& \. H; b: W4 t1 h[mysqld_safe]
# w2 E# L$ s; Vlog-error=/var/log/mysqld.log
8 m% |+ h! b% S" rpid-file=/var/run/mysqld/mysqld.pid' U; `4 D6 \! I* x
6 A E( V' `$ R) d6 z$ \9 ^! x+ j[mysql]
: T. \( M; B w- y( Adefault-character-set = utf87 y' |& u" y/ C! m
設定 MySQL 服務隨系統一起啟動6 B3 P& E+ ]6 U4 P4 m; R
# chkconfig mysqld on, c# C' F5 s* K/ V9 j# M# U9 w% Z
' Q3 |9 S5 z( q$ z5 {- K8 l# q" R( E3 r
確認 MySQL 自動啟動有打開
! x: f2 T; X% @ # chkconfig --list mysqld
& X: y) ]1 E8 R* Y; g# ]# I 如果2--5為on的狀態就OK9 P+ P; v0 ]9 @" }* ^0 v$ i* z
mysqld 0: off 1: off 2: on 3: on 4: on 5: on 6: off5 E/ B! e( l* h: ^3 w$ _: g
啟動 MySQL 服務( o0 \) V, S1 D" {& z' {
# 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 ) T) N& W/ s+ V! |/ I
啟動 MySQL 以後,必須設定 root 的密碼
& s- ^ L1 D8 n( `* p # 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 輸入密碼 1 f3 l" x0 O# D; T. O& K2 N
[重新安裝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, L9 s5 g. w( {' p5 K
mysql_install_db --user=mysql --ldata=/var/lib/mysql/ ===>check /var/lib/mysql/內已建立許多DB
7 T" q2 u; Z# X$ s* `& B: r
; Y/ Q/ d5 l7 i. I3 I, a. i: z' U
升級成最新版: https://www.cadch.com/modules/news/article.php?storyid=227 |