安装环境如下所示:
Centos 7.4 64 位
Mysql 5.7
下载安装MySQL Yum
ssh连接目标服务器后,用 wget 下载 5.7 版本的MySQL Yum
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
然后用 yum 安装MySQL Yum
yum localinstall mysql57-community-release-el7-8.noarch.rpm
然后用命令检测 MySQL Yum是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
安装成功后你会看到下面的提示。
image安装 MySQL
yum install mysql-community-server
启动 MySQL
systemctl start mysqld
//如此类推
systemctl stop mysqld
systemctl restart mysqld
//第二种,容易记
service msyqld start
service msyqld stop
service msyqld restart
设置开机启动 MySQL
systemctl enable mysqld
systemctl daemon-reload
修改 MySQL 密码
因为安装后,会自动给 root 生成默认密码的,我们用下面命令查看密码,5ejRwZBgquL就是默认密码了。
[root@VM_65_249_centos ~]# grep 'temporary password' /var/log/mysqld.log
2018-06-13T04:04:42.144765Z 1 [Note] A temporary password is generated for root@localhost: #5ejRwZBgquL
登录
mysql -u root -p
修改密码
因为 mysql 设置了密码安全检查插件,你的密码必须包含大小写英文,数字,字符且不小于8位,需注意,以英文分号结束。否则会报下面的错。
set password for 'root'@'localhost'=password('YourNewPassword123!');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements //不通过密码安全插件检查
远程连接
因为 root 用户默认禁止远程连接,所以你可以改变策略让 root 远程连接,或者创建新用户去远程连接。这里为了安全起见,新建用户 ppjun
GRANT ALL PRIVILEGES ON *.* TO 'ppjun'@'%' IDENTIFIED BY 'YourNewPassword123!' WITH GRAN;
这里的意思是让用户 ppjun 分配本机所有数据库所有表的权限,并且设置密码 YourNewPassword123!
配置默认 UTF8 编码
vi /etc/my.cnf
在[mysqld]下面新增
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
然后在 mysql 里面看到编码是utf8
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)
以上。
网友评论