1、 安装mysql 1) 挂载光盘
2) 安装依赖程序 [root@centos01 ~]# yum -y install ncurses-devel cmake
3) 创建管理mysql账户 [root@centos01 ~]# groupadd mysql [root@centos01 ~]# useradd -M -s /sbin/nologin -g mysql mysql
4) 配置mysql数据库,卸载光盘切换光盘,挂载光盘
进入mysql cd /usr/src/mysql-5.5.22/
配置 [root@centos01 mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc
5) 编译安装mysql [root@centos01 ~]# make && make install
6) 查看是否安装成功
2、 初始化配置mysql 1) 生成mysql主配置文件 [root@centos01 mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
2) 生成服务控制文件 [root@centos01 mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld [root@centos01 mysql-5.5.22]# chmod +x /etc/init.d/mysqld
3) 添加为系统服务设置开机自动启动 [root@centos01 ~]# chkconfig --add mysqld [root@centos01 ~]# chkconfig --level 35 mysqld on
4) 优化mysql [root@centos01 ~]# vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin/ [root@centos01 ~]# source /etc/profile
5) 设置mysql目录的所有者 [root@centos01 ~]# chown -R mysql:mysql /usr/local/mysql/
6) 初始化mysql服务 [root@centos01 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
7) 重新启动mysql服务,设置服务开机自启 [root@centos01 ~]# systemctl start mysqld [root@centos01 ~]# systemctl enable mysqld
8) 监听mysql3306端口 [root@centos01 ~]# netstat -anptu | grep 3306
9) 设置mysql初始密码 [root@centos01 ~]# mysqladmin -uroot password
登录mysql
[root@centos01 ~]# mysql -uroot -ppwd@123
3、 数据库的管理 1) 登录mysql数据库 [root@centos01 ~]# mysql -uroot -ppwd@123
2) 查看数据库 mysql> show databases;
3) 切换数据库mysql中 mysql> use mysql;
4) 创建数据库benet mysql> create database benet;
查看
5) 删除创建的benet数据库 mysql> drop database benet;
查看
4、 表的管理 1) 创建student表 mysql> create table benet.student (mysql> create table benet.student (姓名 char(10),性别 char(3),成绩 int,身份证号码 char(16),primary key (身份证号码));
2) 查看表的结构 mysql> desc benet.student;
查看创建的表 mysql> show tables;
3) 删除表 mysql> drop table benet.student;
5、 表中记录的管理 1) 表中插入数据 mysql> insert into benet.student values (‘lijingjing’,‘男’,100,‘111111111111111’);
查看 mysql> select * from benet.student;
2) 查看姓名和成绩列 mysql> select 姓名,成绩 from benet.student
3) 匹配身份证号码将性别修改为女 mysql> update benet.student set 性别=‘女’ where 身份证号码=‘222223331111111’;
4) 删除表中记录 mysql> delete from benet.student where 姓名=‘lijingjing’;
5) 删除表中所以记录 mysql> delete from benet.student;
6、 维护数据库和数据库权限的管理 1) 授权lijing账户拥有完全控制权限对benet数据库所以表 mysql> grant all on benet.* to ‘lijing’@‘localhost’ identified by ‘pwd@123’;
2) 查看授权权限 mysql> show grants for ‘bob’@‘localhost’;
3) 使用lijing登录数据库 [root@centos01 ~]# mysql -ulijing -ppwd@123
验证
4) 撤销授权,撤销所有权限 mysql> revoke all on benet.* from ‘tom’@‘localhost’;
5) 授权root通过客户端192.168.100.30登录mysql服务 安装mysql客户端
授权root远程主机登录
远程主机登录mysql服务
