官网下载地址:http://dev.mysql.com/downloads/mysql/5.5.html#downloads
网易地址:http://mirrors.sohu.com/mysql/
为了方便以后扩展,先创建逻辑卷
创建分区过程省略.....
[[email protected] ~]# pvcreate /dev/sda{6,7} [[email protected] ~]# vgcreate myvg /dev/sda{6,7} [[email protected] ~]# lvcreate -L 8G -n mydata myvg [[email protected] ~]# mke2fs -t ext4 -L MYDATA -b 4096 /dev/myvg/mydata
编辑/etc/fstab实现自动挂载
LABEL=MYDATA /mydata ext4 defaults 0 0
创建mydata目录作挂载点
[[email protected] ~]# mkdir /mydata [[email protected] ~]# mount -a
创建系统用户mysql并让其对/mydata/data有属主属组权限
[[email protected] ~]# mkdir /mydata/data [[email protected] ~]# useradd -r mysql [[email protected] ~]# chown -R mysql:mysql /mydata/data/
安装之前先查看系统当前是否有在监听3306端口,如果有则关闭
[[email protected] mysql]# ss -tanl
解压通用包至/usr/local目录下
[[email protected] ~]# tar xf mysql-5.5.38-linux2.6-x86_64.tar.gz -C /usr/local/
创建链接
[[email protected] local]# ln -sv mysql-5.5.38-linux2.6-x86_64 mysql
修改mysql目录下所有文件盒目录属组为mysql
[[email protected] mysql]# chown -R root:mysql /usr/local/mysql/*
创建并修改my.cnf配置文件
[[email protected] support-files]# cp my-huge.cnf /etc/my.cnf [mysqld]中添加一行设置数据目录:datadir = /mydata/data
创建服务脚本
[[email protected] support-files]# cp mysql.server /etc/rc.d/init.d/mysqld
启动服务之前先执行初始化脚本
[[email protected] mysql]# scripts/mysql_install_db --user=mysql -- datadir=/mydata/data
启动服务
[[email protected] mysql]# service mysqld start
导出man文档
[[email protected] ~]# vim /etc/man.config 添加:MANPATH /usr/local/mysql/man
导出头文件
[[email protected] ~]# ln -sv /usr/local/include /usr/include/mysql
导出库文件
[[email protected] ~]# vim /etc/ld.so.conf.d/mysql.conf 添加:/usr/local/mysql/li
重新载入
[[email protected] ~]# ldconfig
到此mysql安装完毕.........
使用mysql客户端之前先导出环境变量
[[email protected] ~]# vim /etc/profile.d/mysql.sh
添加:export PATH=/usr/local/mysql/bin:$PATH
[[email protected] ~]# . /etc/profile.d/mysql.sh
基本语句
以root用户连接mysql
[[email protected] ~]# 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 [email protected] [IDENTIFIED BY ‘password‘];
修改用户密码
1.
mysql> SET PASSWORD FOR ‘myuser‘@‘192.168.1.%‘=PASSWORD(‘654321‘);
mysql> FLUSH PRIVILEGES;(立即生效)
2.
[[email protected] ~]# mysqladmin -umyuser password ‘654321‘ -p
mysql通用二进制格式安装与基本语句
时间: 2024-10-13 11:31:15