日期:2014-05-16 浏览次数:20921 次
以前使用的数据库PostgreSQ占用资源稍微有点大, 打算将数据库切换到MySQL下试试效果,安装和简单的使用流程记录如下(terminal 输入以下指令):
1: 安装
# yum install mysql-server.i686
2: 切换至MySQL console
# mysql
3: mysql 平台下 创建数据库(demo_db)
mysql> create database demo_db default character set utf8;
4: 创建用户[demo_user],密码[demo_user] ,并赋予该用户对demo_db数据库的访问权限。
mysql> grant all privileges on demo_db.* to 'demo_user'@'localhost' identified by 'demo_user';
mysql> grant all privileges on demo_db.* to 'demo_user'@'%' identified by 'demo_user';
5: 退出MySQL console
mysql> exit
6:以刚创建的[demo_user]用户身份运行MySQL console
# mysql -u demo_user -p
7: 指定要访问的数据库
mysql> use demo_db;
以上步骤就完成了MySQL的安装和用户的创建等等,下面来看看如何创建Table 以及如何访问他们
8: 创建一个table
CREATE TABLE demo_table
(
id_number integer NOT NULL,
id character varying(30),
pass character varying(30),
fullname text,
CONSTRAINT demo_table_pkey PRIMARY KEY (id_number)
);
9: 往demo_table 中写入固定内容
insert into demo_table (id_number, id, pass, fullname) values (0, "demo_id", "demo_password", "demo_fullname");
10: 设定MySQL的文本格式为[UTF-8]
A: 打开配置文件# gedit /etc/my.cnf
B: 配置文件中添加带★部分的内容
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
★character-set-server=utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
★[mysql]
★default-character-set=utf8
通过以上步骤就创建了一个Table,并往该Table中插入了一条记录。