Centos7 安装 MySql
1.下载安装源
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
yum localinstall mysql57-community-release-el7-8.noarch.rpm
2.检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
3.安装mysql
yum install mysql-community-server
4.启动mysql服务
systemctl start mysqld
查看mysql状态:systemctl status mysqld
5.设置开机自启动:
systemctl enable mysqld
systemctl daemon-reload
6.设置root密码
先查看root的密码:
grep 'temporary password' /var/log/mysqld.log
然后登陆mysql:
mysql -u root -p
按照提示,输入root密码进入mysql
修改root密码:
mysql> set password for 'root'@'localhost'=password('Mysql.123456');
密码要求包含大小写、特殊字符、数字
7.添加一个远程用户
为安全起见,不要用root连接,所以建一个远程用户来使用
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user1'@'%' IDENTIFIED BY 'User.123456' WITH GRANT OPTION;
8.修改默认编码为utf8
这个设置可以解决中文乱码问题
mysql> exit 退出到centos命令行,编辑/etc/my.cnf文件
vi /etc/my.cnf
添加以下语句
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
9.重新启动mysql服务器
service mysqld restart
进入mysql,查看编码状态
show variables like '%character%';