美文网首页
MySQL 安装、配置

MySQL 安装、配置

作者: qyfl | 来源:发表于2019-03-16 22:17 被阅读0次

1. 安装

yum -y install mysql-server

2. 修改配置

CentOS

vi /etc/my.cnf
#在[mysqld]标签下添加
init_connect='SET collation_connection = utf8_unicode_ci' 
init_connect='SET NAMES utf8' 
character-set-server=utf8 
collation-server=utf8_unicode_ci 
skip-character-set-client-handshake
default-time-zone = '+8:00' # 更改时区(东八区)


vi /etc/my.cnf.d/client.cnf
#在[client]中添加
default-character-set=utf8


vi /etc/my.cnf.d/mysql-clients.cnf
#在[mysql]中添加
default-character-set=utf8

Ubuntu

vim /etc/mysql/mariadb.conf.d/50-server.cnf 

#bind-address = 127.0.0.1     注释掉这行

#在[mysqld]标签下添加
skip-character-set-client-handshake  

3. 启动 MySQL

systemctl start mysqld     #启动 MySQL 或
service mysqld start       #启动 MySQL

systemctl enable mysqld      #设置开机启动

#ubuntu
update-rc.d mysql defaults
systemctl start mysql

4. 通过日志文件查找默认密码

// 密码是 /!2Ja(Ic8Cw>
[root@db ~]# cat /var/log/mysqld.log | grep "temporary password"
2018-07-19T08:46:38.692490Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: /!2Ja(Ic8Cw>

5. 命令行登陆 mysql 数据库

[root@db ~]# mysql -u root -p
// 密码就是上面查询出来的密码
Enter password:
mysql> 

6. 查看字符集

show variables like "%character%";
show variables like "%collation%";

7. 修改 root 密码,开启远程访问

-- 更改加密方式及密码
-- mysql 自 5.7 后密码要求至少包含一个大写字母、一个小写字母、一个特殊符号、一个数字。且密码长度至少为8个字符
ALTER USER 'root'@'localhost' IDENTIFIED BY 'qwer`123AA' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'qwer`123AA';

-- 更改 root 的 访问地址
mysql> use mysql;
mysql> update user set host='%' where user='root';

-- 刷新
FLUSH PRIVILEGES;

8. 创建新用户、授权

mysql>create user ‘mysql’@localhost identified by '123456';

mysql>grant all on *.* to ‘mysql’@localhost identified by '123456';

mysql>grant all privileges on *.* to ‘mysql’@'%' identified by '123456';

相关文章

网友评论

      本文标题:MySQL 安装、配置

      本文链接:https://www.haomeiwen.com/subject/jopemqtx.html