建议使用docker安装
安装
先检测是否已经存在mysql,存在删除
$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
$ rpm -e mysql-libs-5.1.52.x86_64 –nodeps
如果不想用root用户,可以创建一个mysql专用的只能使用shell的用户来操作
语句:adduser –system –shell /bin/sh –create-home –home-dir /home/mysql mysql
新建tomcat用户目录,进入下载源码
[tomcat@localhost /]$ sudo mkdir service
[tomcat@localhost /]$ sudo chown -R tomcat:tomcat service/
[tomcat@localhost /]$ cd service
[tomcat@localhost service]$ mkdir src
[tomcat@localhost service]$ cd src
[tomcat@localhost src]$ sudo wget https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
安装
[tomcat@localhost src]$ sudo yum localinstall mysql57-community-release-el7-11.noarch.rpm
检查mysql源是否安装成功
[tomcat@localhost src]$ yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 42
mysql-tools-community/x86_64 MySQL Tools Community 55
mysql57-community/x86_64 MySQL 5.7 Community Server 227
安装mysql服务,这一步如果下载安装慢的话,可以Ctrl+c停止,重新安装
[tomcat@localhost src]$ sudo yum install mysql-community-server
启动服务
[tomcat@localhost src]$ sudo systemctl start mysqld
设置开机启动
[tomcat@localhost src]$ sudo systemctl enable mysqld
[tomcat@localhost src]$ sudo systemctl daemon-reload
获取当前默认密码为:4aisNuwDC7%h
[tomcat@localhost src]$ grep "temporary password" /var/log/mysqld.log
2017-12-07T15:21:13.545299Z 1 [Note] A temporary password is generated for root@localhost: tzeVWyM*g0ut
登录,并且修改密码为MyNewPass4!
[root@localhost local]# mysql -uroot -p
mysql> ALTER USER "root"@"localhost" IDENTIFIED BY "MyNewPass4!";(默认的密码策略必须是大写小写数字符号一起,并且长度不能少于8位,源码安装一个大坑。用tar包是没有这个问题的。。。。)
或者
mysql> set password for "root"@"localhos"=password("MyNewPass4!");
那么接下来为了是密码简单好记一些,我们修改密码策略
先查看密码策略
mysql> show variables like ‘%password%’;
validate_password_policy:密码策略,默认为MEDIUM策略
validate_password_dictionary_file:密码策略文件,策略为STRONG才需要 validate_password_length:密码最少长度
validate_password_mixed_case_count:大小写字符长度,至少1个
validate_password_number_count :数字至少1个
validate_password_special_char_count:特殊字符至少1个
上述参数是默认策略MEDIUM的密码检查规则。
MySQL官网密码策略详细说明:http://dev.mysql.com/doc/refman/5.7/en/validate-password-options-variables.html#sysvar_validate_password_policy
[root@localhost ~]# vi /etc/my.cnf
加入validate_password = off (没有策略)
或者
validate_password_policy=0 (策略最低)
设置远程访问
mysql> GRANT ALL PRIVILEGES ON *.* TO "dream"@"%" IDENTIFIED BY "Dream@123456";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
修改编码
/etc/my.cnf
我的mysql没有[client]这个字段,首先添加上,
在[client]段增加下面代码default-character-set=utf8(网上还有提到其他的设置语句,是以前的版本,现在不用了)
在[mysqld]段增加下面的代码character-set-server=utf8和collation-server=utf8_general_ci
基本命令
启动MySQL服务:systemctl start mysqld
查看MySQL的启动状态:systemctl status mysqld
重启MySQL服务:systemctl restart mysqld