1,安装mysql服务
yum install mysql mysql-server
查看mysql版本信息 : yum list mysql mysql-server
安装完成后,配置文件路径:/etc/my.cnf
2,启动mysql服务,并配置为随系统自启动
systemctl start mysqld.service
systemctl enable mysqld.service
3,mysql安全设置
/usr/bin/mysql_secure_installation
或者通过命令只设置root用户密码:mysqladmin -u root password [your_password_here]
4,创建DataBase和用户
root登录数据库
# mysql -u root -p
创建数据库demodb
mysql> create database demodb;
如果需要支持中文,则加上DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
创建用户demodb_cat,并指定从本机访问
mysql> CREATE USER 'demodb_cat'@'localhost' IDENTIFIED BY 'cat';
为用户授权
mysql>grant all privileges on demodb.* to demodb_cat@'localhost' identified by 'cat';
或者部分授权 mysql> grant select,update on demodb.* to demodb_cat@'localhost' identified by 'cat';
重载权限表
mysql> flush privileges;
退出
mysql> quit;
以新用户身份登录
#mysql -u demodb_cat -p
5, 创建测试表
mysql> create table users(id int(8) auto_increment not null, name varchar(32) not null, passwd char(32), telephonenum varchar(16), createdate date, primary key(id, name));
mysql> desc users;
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| id | int(8) | NO | PRI | NULL | auto_increment |
| name | varchar(32) | NO | PRI | NULL | |
| passwd | char(32) | YES | | NULL | |
| telephonenum | varchar(16) | YES | | NULL | |
| createdate | date | YES | | NULL | |
+--------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
6, 插入测试数据
mysql> insert into users(name, passwd, telephonenum, createdate) values("cat", "cat", "1380000000", now());
Query OK, 1 row affected, 1 warning (0.04 sec)
mysql> select * from users;
+----+------+--------+--------------+------------+
| id | name | passwd | telephonenum | createdate |
+----+------+--------+--------------+------------+
| 1 | cat | cat | 1380000000 | 2012-11-06 |
+----+------+--------+--------------+------------+
1 row in set (0.00 sec)
7, 执行sql脚本
mysql> source /data/Work/bubinglv-service/sql-script/test.sql;