1. yum install mysql
2. yum install mysql-server yum install mysql-devel
3. /etc/rc.d/init.d/mysql restart
4. mysql -u root
5. grant 添加用户
格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"
6. use 数据库名称
7. flush privileges;
8. 修改密码
格式:mysqladmin -u用户名 -p旧密码 password 新密码
9. 连接mysql
格式: mysql -h主机地址 -u用户名 -p用户密码
10.显示命令
1、显示数据库列表。
show databases;
刚开始时才两个数据库:mysql和test。mysql库很重要它里面有mysql的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。
2、显示库中的数据表:
use mysql;
show tables;
3、显示数据表的结构:
describe 表名;
4、建库:
create database 库名;
5、建表:
use 库名;
create table 表名 (字段设定列表);
6、删库和删表:
drop database 库名;
drop table 表名;
7、将表中记录清空:
delete from 表名;
8、显示表中的记录:
select * from 表名;
错误处理:
1. 错误信息:
Stopping MySQL: [FAILED]
Initializing MySQL database: Neither host 'vm0000182' nor 'localhost' could be looked up with
/usr/bin/resolveip
Please configure the 'hostname' command to return a correct hostname.
If you want to solve this at a later stage, restart this script with
the --force option
[FAILED]
原因: 原因是/etc/hosts 文件为空的关系。
修改方法:在 /etc/hosts 文件中添加下面信息:
#localhost
127.0.0.1 localhost.localdomain localhost