CentOS上mysql-server的安裝指南(Linux安裝mysql實戰指南)
0:確定系統信息:
[root@systdt mysql]# cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m
一:yum 方式安裝
[op1@VMS06968 ~]$ yum list mysql*
Loaded plugins: downloadonly, fastestmirror, security
Determining fastest mirrors
Installed Packages
MySQL-client.x86_64 5.6.21-1.el6 @custom
mysql-libs.x86_64 5.1.66-2.el6_3 @anaconda-CentOS-201303020151.x86_64/6.4
Available Packages
MySQL-devel.x86_64 5.6.21-1.el6 custom
MySQL-python.x86_64 1.2.3-0.3.c1.1.el6 base
MySQL-server.x86_64 5.6.21-1.el6 custom
##安裝server端
[op1@VMS06968 ~]$ yum install mysql-server
#安裝client端
[op1@VMS06968 ~]$ yum install mysql
如果安裝的過程中報錯,刪除mysql相關lib,命令如下:;然後再執行上述安裝的兩個步驟;
[op1@VMS06968 ~]$ yum remove mysql*
二:認識mysql的安裝目錄:
2.1、數據庫目錄 /var/lib/mysql/
2.2、配置文件 /usr/share/mysql(mysql.server命令及配置文件)
2.3、相關命令 /usr/bin(mysqladmin mysqldump等命令)
2.4.1、啟動腳本1 /etc/rc.d/init.d/mysql(啟動腳本文件mysql的目錄)
2.4.2、啟動腳本2 /etc/init.d/mysql(啟動腳本文件mysql的目錄)
2.5mysql的配置文件 /usr/my.cnf (find 出來即可)
三:編輯/usr/my.cnf文件內容如下:
[root@systdt mysql]# vi /usr/my.cnf
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
no-beep
bind-address = 0.0.0.0
port=3306
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
default-storage-engine=INNODB #默認數據儲存格式
max_connections=10
innodb_buffer_pool_size=256M #內存
query_cache_size=30M
[mysql]
default-character-set = utf8
四:重啟mysql服務及其修改默認密碼:
1)mysqladmin -u root password 'newpassword' 更改密碼
如果有報錯如下:
[root@systdt mysql]#mysqladmin -u root password 'root'
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
1、停用mysql服務:# /etc/rc.d/init.d/mysqld stop
2、輸入命令:# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
3、登入數據庫:# mysql -u root mysql
4、mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD('root')where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
5、重啟服務:# /etc/init.d/mysql restart
如果用新用戶名,密碼登陸進去報錯如下:
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
6、在執行一下:mysqladmin -u root -proot password 'root' 即可,至此root用戶可以正常使用;
# mysql -u root -proot #即可正常使用數據了!
五:啟動mysql服務,並設定為系統服務:
# chkconfig mysqld on ← 設置MySQL服務隨系統啟動自啟動
# chkconfig –list mysqld ← 確認MySQL自啟動mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 如果2–5為on的狀態就OK
#service mysqld start ←啟動服務(# /etc/rc.d/init.d/mysqld start也可以)
六:刪除匿名用戶和測試數據庫:
delete from mysql.user where user=”; ← 刪除匿名用戶
select user,host from mysql.user; ← 查看用戶信息
select version(),current_date; #當前版本信息,日期和數據庫:
show databases; ← 查看系統已存在的數據庫
drop database test; ← 刪除名為test的空數據庫