第一步,查看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)