首页 > MySQL > mysql启动的四种方式
2015
09-21

mysql启动的四种方式

在创建库的时候指定字符集
GBK: create database  database_name  DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

UTF8: CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

在创建表的时候你可以通过添加一个ENGINE 或TYPE 选项到CREATE TABLE语句来告诉MySQL你要创建什么类表并指定表的存储引擎:

CREATE TABLE t (i INT) ENGINE = INNODB;

CREATE TABLE t (i INT) TYPE = MEMORY;

要把一个表从一个类型转到另一个类型,可使用ALTER TABLE语句,这个语句指明新的类型:

ALTER TABLE t ENGINE = MYISAM;

ALTER TABLE t TYPE = BDB
mysql 建表字符集

1.列出MYSQL支持的所有字符集:
SHOW CHARACTER SET;

2.当前MYSQL服务器字符集设置
SHOW VARIABLES LIKE ‘character_set_%’;

3.当前MYSQL服务器字符集校验设置
SHOW VARIABLES LIKE ‘collation_%’;

4.显示某数据库字符集设置
show create database 数据库名;

5.显示某数据表字符集设置
show create table 表名;

6.修改数据库字符集
alter database 数据库名 default character set ‘utf8’;

7.修改数据表字符集
alter table 表名 default character set ‘utf8’;

8.建库时指定字符集
create database 数据库名 character set gbk collate gbk_chinese_ci;

9.建表时指定字符集
CREATE TABLE `mysqlcode` (
`id` TINYINT( 255 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`content` VARCHAR( 255 ) NOT NULL  www.2cto.com
) TYPE = MYISAM CHARACTER SET gbk COLLATE gbk_chinese_ci;

库字符集,在my.cnf中缺少了如下代码:
[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8

10.修改数据库的字符集
mysql>use mydb
mysql>alter database mydb character set utf-8;

创建数据库指定数据库的字符集
mysql>create database mydb character set utf-8;

通过配置文件修改:

修改/var/lib/mysql/mydb/db.opt
default-character-set=latin1
default-collation=latin1_swedish_ci
为  www.2cto.com
default-character-set=utf8
default-collation=utf8_general_ci

11.MySQL服务器能够支持多种字符集。可以使用SHOW CHARACTER SET语句列出可用的字符集:

mysql> SHOW CHARACTER SET;

如果不加以上代码,那么即便MYSQL编译安装时指定的编码是UTF8,那么在建库时其默认编码仍是LATIN1,而由于字符集的继承性,库中的表也是LATIN1的了。mysql的四种启动方式:
1、mysqld
启动mysql服务器:./mysqld –defaults-file=/etc/my.cnf –user=root
客户端连接:
mysql –defaults-file=/etc/my.cnf
or
mysql -S /tmp/mysql.sock

2、mysqld_safe
启动mysql服务器:./mysqld_safe –defaults-file=/etc/my.cnf –user=root &
客户端连接:
mysql –defaults-file=/etc/my.cnf
or
mysql -S /tm/mysql.sock

3、mysql.server
cp -v /usr/local/mysql/support-files/mysql.server /etc/init.d/
chkconfig –add mysql.server
启动mysql服务器:service mysql.server {start|stop|restart|reload|force-reload|status}
客户端连接:同1、2

4、mysqld_multi
mkdir $MYSQL_BASE/data2
cat <<-EOF>> /etc/my.cnf
[mysqld_multi]
mysqld    = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /user/local/mysql/bin/mysqladmin
user = mysqladmin
password = mysqladmin

[mysqld3306]
port            = 3306
socket          = /tmp/mysql3306.sock
pid-file    = /tmp/mysql3306.pid
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
basedir        = /usr/local/mysql
datadir        = /usr/local/mysql/data

[mysqld3307]
port            = 3307
socket          = /tmp/mysql3307.sock
pid-file    = /tmp/mysql3307.pid
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
basedir        = /usr/local/mysql
datadir        = /usr/local/mysql/data2
EOF

#mysql -S /tmp/mysql3306.sock
mysql>GRANT SHUTDOWN ON *.* TO ‘mysqladmin’@’localhost’ identified by ‘mysqladmin’ with grant option;

#mysql -S /tmp/mysql3307.sock
mysql>GRANT SHUTDOWN ON *.* TO ‘mysqladmin’@’localhost’ identified by ‘mysqladmin’ with grant option;

启动mysql服务器:./mysqld_multi –defaults-file=/etc/my.cnf start 3306-3307
关闭mysql服务器:mysqladmin shutdown


留下一个回复

你的email不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据