一、 查看系統自帶mysql是否已安裝。mysql
[root@develop bin]# yum list installed | grep mysqllinux
mysql-libs.x86_64 5.1.73-5.el6_6 @base sql
二、 如有自帶安裝的mysql,將其卸載數據庫
[root@develop ~]# yum –y remove mysql-libs.x86_64centos
如有多個依賴文件則依次卸載。服務器
三、 使用yum安裝mysql數據庫。ide
[root@develop ~]# yum -y install mysql-server mysql mysql-develui
命令將:mysql-server、mysql、mysql-devel都安裝好,當結果顯示爲「Complete!」即安裝完畢。spa
注:安裝mysql只是安裝了數據庫,只有安裝mysql-server才至關於安裝了客戶端。.net
四、 啓動mysql服務,在終端輸入:
service mysqld start或者/etc/init.d/mysqld start
五、 設置MySQL服務隨系統啓動自啓動
[root@develop ~]# chkconfig mysqld on
檢查啓動狀態
[root@develop ~]# chkconfig --list mysqld
mysqld 0:關閉1:關閉2:啓用3:啓用4:啓用5:啓用6:關閉
六、 查看剛安裝mysql數據庫版本信息
[root@develop ~]# rpm -qi mysql-server
Name : mysql-server Relocations: (not relocatable)
Version : 5.1.73 Vendor: CentOS
Release : 5.el6_6 Build Date: 2015年06月22日 星期一 21時08分32秒
Install Date: 2015年12月23日 星期三 11時00分00秒 Build Host: c6b9.bsys.dev.centos.org
Group : Applications/Databases Source RPM: mysql-5.1.73-5.el6_6.src.rpm
Size : 25882979 License: GPLv2 with exceptions
Signature : RSA/SHA1, 2015年06月22日 星期一 22時30分08秒, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://www.mysql.com
Summary : The MySQL server and related files
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MySQL server and some accompanying files and directories.
七、 建立root管理用戶
查看文件安裝路徑
[root@develop ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
在終端輸入:cd /usr/bin/ 目錄下 建立root用戶密碼
[root@develop bin]# mysqladmin -u root -p password 密碼
八、 登陸mysql系統
[root@develop bin]# mysql -uroot -p
Enter password: [輸入原來密碼]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
九、建立遠程用戶
使用grant語句添加:首先在數據庫本機上用root用戶
登陸mysql(我是用遠程控制linux服務器,至關於在服務器本機登陸mysql了),而後輸入:
mysql>grant all privileges on *.* to admin@localhost identified by 'something' with grant option;
添加一個用戶admin並受權經過本地機(localhost)訪問,密碼"something"。
mysql>grant all privileges on *.* to admin@"%" identified by 'something' with grant option;
添加一個用戶admin並受權可從任何其它主機發起的訪問(通配符%)。使用這一條語句便可。