【MySQL笔记】mysql源码安装/配置步骤及支持中文gbk/gb2312编码的配置方法 好久之前的学习笔记,分享出来,希望能帮助到更多初学者 备注:本笔记以mysql-5.1.73版本为例进行说明 1. mysql源码编译/安装步骤 1) 官网下载mysql源码并解压 2) cd至源码目录,执行
【MySQL笔记】mysql源码安装/配置步骤及支持中文gbk/gb2312编码的配置方法好久之前的学习笔记,分享出来,希望能帮助到更多初学者
备注:本笔记以mysql-5.1.73版本为例进行说明
1. mysql源码编译/安装步骤
1) 官网下载mysql源码并解压
2) cd至源码目录,执行
./configure --prefix=/home/slvher/tools/mysql-5.1.73 --with-charset=gbk --with-charset=gb2312 --with-extra-charsets=all --with-plugins=max-no-ndb
shell> make shell> make install
./bin/mysql_install_db --basedir=/home/slvher/tools/mysql-5.1.73 --datadir=/home/slvher/tools/mysql-5.1.73/db-data ./bin/mysql_install_db --user=slvher
./bin/mysqld_safe &
./bin/mysqladmin shutdown -uroot -p
shell> mysql -uroot mysql> show character set;
2. 安装完成并启动mysqld_safe后的访问权限配置
1) 设定mysql server的root密码
root密码默认为空(因此,运行mysql -uroot可直接登录;此外,登录后运行"select User, Host, Password from mysql.user"可以看到root的Password那个字段为空),所以需要设定root密码,方法有几种:
a. 使用set password语句:
shell> mysql -u root mysql> set password for 'root'@'localhost' = PASSWORD('xxx'); # 其中xxx为新密码 mysql> set password for 'root'@'host_name' = PASSWORD('xxx'); # 其中host_name为机器名 mysql> set password for 'root'@'127.0.0.1' = PASSWORD('xxx');
shell> mysql -u root mysql> update mysql.user set Password = PASSWORD('xxx') where User = 'root'; mysql> flush privileges; # 该语句会让mysql server重新读取权限表
shell> mysqladmin -u root password "xxx" shell> mysqladmin -u root -h host_name passord "xxx"
2) 添加新用户并授权
由于root权限过大,有必要为mysql添加normal user并设定其权限,可通过以下步骤实现(假设已登录了mysql server所在机器):
shell> mysql -u root -pxxx # 注意-p与password(假设为"xxx")间无空格,可省去输入密码的交互过程 mysql> create user work; mysql> grant select on db1.test_table to 'user'@'localhost' identified by 'xxx';
mysql> grant all privileges on *.* to 'user'@'localhost' identified by 'xxx';
mysql> grant select, insert on db1.test_table to 'user'@'%' identified by 'xxx';
【参考资料】
1.
mysql reference manual
2. mysql: unknown variable 'character-set-server=utf8'解决方法
========================= EOF ==========================