Centos7安装mysql7
从官方下载 rpm
https://repo.mysql.com/
wget https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
执行安装yum源
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
安装mysql服务器
yum -y install mysql-community-server
启动mysql服务
systemctl start mysqld
查看临时的root
密码
less /var/log/mysqld.log | grep 'temporary password'
...password is generated for root@localhost: A*xer0Hj*RQU
临时密码就是:A*xer0Hj*RQU
使用临时密码登录mysql服务
mysql -uroot -p"A*xer0Hj*RQU"
第一件大事儿就是修改root
密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql@112233';
mysql5.7默认安装了密码安全检查插件(
validate_password
),默认密码检查策略要求密码必须包含:大小写字母,数字和特殊符号,并且长度不能少于8位
否则会提示ERROR 1819 (HY000):Your password does not satisfy the current policy requirements
授权用户可以在远程服务器登录(非必须)
一般不会直接使用
root
作为远程登录账户,而是新建一个用户
GRANT ALL PRIVILEGES ON *.* TO 'KevinBlandy'@'%' IDENTIFIED BY 'Mysql@112233' WITH GRANT OPTION;
FLUSH PRIVILEGES;
ALL PRIVILEGES
所有权限*.*
任意数据库下的任意数据表KevinBlandy
用户名%
任意ippass
登录密码
退出登录
quit
修改编码
修改配置文件:
/etc/my.cnf
vim /etc/my.cnf
添加配置
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
重启mysql服务
systemctl restart mysqld
登录,查看编码
mysql -uroot -p"Mysql@112233"
show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
基本的维护命令
启动
systemctl start mysqld
停止
systemctl stop mysqld
重启
systemctl restart mysqld
状态查看
systemctl status mysqld
开启自启动
systemctl enable mysqld
禁止自启动
systemctl disable mysqld
最后
记得开放端口,以及云服务器的安全组。