官网下载地址:http://dev.mysql.com/downloads/mysql/5.5.html#downloads
搜狐地址:http://mirrors.sohu.com/mysql/
为了方便以后扩展,先创建逻辑卷
创建分区过程省略.....
[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目录作挂载点
[root@localhost ~]# mkdir /mydata [root@localhost ~]# mount -a
创建系统用户mysql并让其对/mydata/data有属主属组权限
[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目录下
[root@localhost ~]# tar xf mysql-5.5.38-linux2.6-x86_64.tar.gz -C /usr/local/
创建链接
[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';