官網下載地址:http://dev.mysql.com/downloads/mysql/5.5.html#downloadshtml
搜狐地址:http://mirrors.sohu.com/mysql/ mysql
爲了方便之後擴展,先建立邏輯卷linux
建立分區過程省略.....
sql
[root@localhost ~]# pvcreate /dev/sda{6,7} [root@localhost ~]# vgcreate myvg /dev/sda{6,7} [root@localhost ~]# lvcreate -L 8G -n mydata myvg [root@localhost ~]# mke2fs -t ext4 -L MYDATA -b 4096 /dev/myvg/mydata
編輯/etc/fstab實現自動掛載
數據庫
LABEL=MYDATA /mydata ext4 defaults 0 0
建立mydata目錄做掛載點vim
[root@localhost ~]# mkdir /mydata [root@localhost ~]# mount -a
建立系統用戶mysql並讓其對/mydata/data有屬主屬組權限bash
[root@localhost ~]# mkdir /mydata/data [root@localhost ~]# useradd -r mysql [root@localhost ~]# chown -R mysql:mysql /mydata/data/
安裝以前先查看系統當前是否有在監聽3306端口,若是有則關閉服務器
[root@localhost mysql]# ss -tanl
解壓通用包至/usr/local目錄下ide
[root@localhost ~]# tar xf mysql-5.5.38-linux2.6-x86_64.tar.gz -C /usr/local/
建立連接spa
[root@localhost local]# ln -sv mysql-5.5.38-linux2.6-x86_64 mysql
修改mysql目錄下全部文件盒目錄屬組爲mysql
[root@localhost mysql]# chown -R root:mysql /usr/local/mysql/*
建立並修改my.cnf配置文件
[root@localhost support-files]# cp my-huge.cnf /etc/my.cnf [mysqld]中添加一行設置數據目錄:datadir = /mydata/data
建立服務腳本
[root@localhost support-files]# cp mysql.server /etc/rc.d/init.d/mysqld
啓動服務以前先執行初始化腳本
[root@localhost mysql]# scripts/mysql_install_db --user=mysql -- datadir=/mydata/data
啓動服務
[root@localhost mysql]# service mysqld start
導出man文檔
[root@localhost ~]# vim /etc/man.config 添加:MANPATH /usr/local/mysql/man
導出頭文件
[root@localhost ~]# ln -sv /usr/local/mysql/include /usr/include/mysql
導出庫文件
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf 添加:/usr/local/mysql/lib
從新載入
[root@localhost ~]# ldconfig
到此mysql安裝完畢.........
使用mysql客戶端以前先導出環境變量
[root@localhost ~]# vim /etc/profile.d/mysql.sh
添加:export PATH=/usr/local/mysql/bin:$PATH
[root@localhost ~]# . /etc/profile.d/mysql.sh
基本語句
以root用戶鏈接mysql
[root@localhost ~]# mysql -uroot -p
顯示有權限訪問的全部數據庫
mysql> show databases;
設置mysql爲默認數據庫
mysql> use mysql
顯示默認數據庫
mysql> select database();
建立數據庫
mysql> CREATE DATABASE mydb;
刪除數據庫
mysql> DROP DATABASE mydb;
顯示服務器參數變量
mysql> show variables;
顯示服務器狀態變量
mysql> show status;
建立用戶(容許myuser用戶從192.168.1.0網段登陸mysql密碼爲123456)
mysql> CREATE USER 'myuser'@'192.168.1.%' IDENTIFIED BY '123456';
刪除用戶
mysql> DROP USER 'myuser'@'192.168.1.%';
用戶受權:
GRANT ALL PRIVILEGES ON dbname.tablename TO username@host [IDENTIFIED BY 'password'];
修改用戶密碼
1.
mysql> SET PASSWORD FOR 'myuser'@'192.168.1.%'=PASSWORD('654321');
mysql> FLUSH PRIVILEGES;(當即生效)
2.
[root@localhost ~]# mysqladmin -umyuser password '654321' -p
表基本語句
新建表tb1,字段爲(ID,Name,Age,Gender,Course)
ID:微數值,無符號,不能爲空,主鍵,自動增加
Name:30個字符,不能爲空,惟一鍵
Age:微數值,無符號
Gender:1個字符,默認爲M
Course:最多50個字符,不能爲空
mysql> CREATE TABLE tb1 (ID TINYINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,Name CHAR(30) NOT NULL UNIQUE KEY,Age TINYINT UNSIGNED,Gender CHAR(1) DEFAULT 'M',Course VARCHAR(50) NOT NULL);
插入數據
mysql> INSERT INTO tb1 (Name,Age,Course) values ('Ling huchong','20','xixingdafa'); mysql> INSERT INTO tb1 values (2,'yangguo',30,'M','anranxiaohunzhang'),(3,'zhangsanfeng',80,'M','taiji');
修改Ling huchong的性別爲F
mysql> UPDATE tb1 SET Gender='F' WHERE Name='Ling huchong';
查詢Ling huchong的性別
mysql> select Gender FROM tb1 where Name='Ling huchong';
刪除性別爲F的行
mysql> DELETE FROM tb1 WHERE Gender='F';