转载

手把手教你在Centos部署Web项目(三) 安装Mysql

1.下载Mysql

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

2.安装yum库

yum localinstall -y mysql57-community-release-el7-7.noarch.rpm

3.启动Mysql服务

systemctl start mysqld.service

4.查看初始密码

grep 'temporary password' /var/log/mysqld.log

5.修改密码

使用初始随机密码登录后MySQL会强制要求修改密码,否则无法正常使用,(密码必须包含小写、大写字母及特殊字符,当然也有其他方法不受此限制,再次不多做描述),修改方法如下:

SET PASSWORD = PASSWORD('your new password');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;

然后退出后即可用新密码登录。

6.远程连接授权

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;

7.修改数据库服务器编码

1.登陆

mysql -u root -p 

输入密码,进入Mysql命令行,输入show variables like '%char%',查看字符集

+----------------------+---------------------
| Variable_name | Value+-----------------------+---------------------
| character_set_client | utf8
| character_set_connection | utf8
| character_set_database | utf8
| character_set_filesystem |utf8
| character_set_results |utf8
| character_set_server | latin1
| character_set_system | utf8
| character_sets_dir | /usr/share/mysql/charsets/
+---------------------+----------------------

显示 server端的编码并不为utf8,下面修改设置

2.修改

cd /etc
vim my.cnf

在[mysqld]下面增加一行代码
character-set-server=utf8

正文到此结束
Loading...