第一步, 查看 CentOS 下是否已经安装 MySQL
输入命令: yum list installed | grep MySQL
第二步, 删除已经安装的 MySQL
输入命令: yum -y remove MySQL
第三步, 查看 yum 库中的 MySQL(非必需的, 查看版本)
输入命令: yum list | grep MySQL
第四步, 从 yum 库中的安装 MySQL
输入命令: yum -y install MySQL MySQL-server MySQL-devel
第五步, 验证是否安装成功
输入命令: rpm -qi MySQL-server
第六步, 启动 MySQL 服务
输入命令: service mysqld start
第七步, 进入 MySQL
输入命令: MySQL -u root
第八步, 设置 root 密码
启动 MySQL:
#service mysqld start
设置 root 密码:
mysql_secure_installation
登陆 root 账号:
MySQL -u root -p
建立远程 root 用户
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你设置的密码' WITH GRANT OPTION;
- MySQL> flush privileges;
设置 utf-8
查看 MySQL 原本的源码
MySQL> show variables like 'character%';
设置编码:
# vi /etc/my.cnf
在 my.cnf 文件中添加如下代码:
- [mysqld]
- character-set-server=utf8
- collation-server=utf8_general_ci
- sql_mode='NO_ENGINE_SUBSTITUTION'
- [MySQL]
- default-character-set = utf8
- [MySQL.server]
- default-character-set = utf8
- [mysqld_safe]
- default-character-set = utf8
- [client]
- default-character-set = utf8
重启 MySQL
#service mysqld restart
再次查看编码:
- # MySQL -uroot -p
- MySQL> show variables like 'character%';
- +--------------------------+----------------------------+
- | Variable_name | Value |
- +--------------------------+----------------------------+
- | character_set_client | utf8 |
- | character_set_connection | utf8 |
- | character_set_database | utf8 |
- | character_set_filesystem | binary |
- | character_set_results | utf8 |
- | character_set_server | utf8 |
- | character_set_system | utf8 |
- | character_sets_dir | /usr/share/MySQL/charsets/ |
- +--------------------------+----------------------------+
- 8 rows in set (0.00 sec)
来源: http://www.jianshu.com/p/08d6185bdc54