数据库
首页 > 数据库> > 一、mysql5.7 rpm 安装(单机)

一、mysql5.7 rpm 安装(单机)

作者:互联网


一、下载需要的rpm包

mysql-community-client-5.7.26-1.el6.x86_64.rpm
mysql-community-common-5.7.26-1.el6.x86_64.rpm
mysql-community-libs-5.7.26-1.el6.x86_64.rpm
mysql-community-server-5.7.26-1.el6.x86_64.rpm

下载地址:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/


二、查看之前有没有安装mysql有就卸载
查看:rpm -qa | grep -i mysql

删除之前所有mysql相关的东西
yum -y remove mysql*
注:如果卸载失败使用如下语句
查看:rpm -qa | grep -i mysql
卸载:rpm -e mysql-community-common-5.7.26-1.el6.x86_64 mysql-community-client-5.7.26-1.el6.x86_64 mysql-community-libs-5.7.26-1.el6.x86_64 mysql-community-server-5.7.26-1.el6.x86_64

三、安装mysql
将如下四个rpm包拷贝到/opt下
然后执行
cd /opt
yum install mysql-community-server-5.7.26-1.el6.x86_64.rpm mysql-community-client-5.7.26-1.el6.x86_64.rpm mysql-community-common-5.7.26-1.el6.x86_64.rpm mysql-community-libs-5.7.26-1.el6.x86_64.rpm
 
service mysqld start    #启动mysql
service mysqld stop     #关闭mysql
service mysqld status   #状态
service mysqld restart  #重启

启动失败就:
rm -fr /var/lib/mysql/*
rm /var/lock/subsys/mysqld
killall mysqld

四、设置密码
 
mysql5.7安装好后默认临时密码放在/var/log/mysqld.log里面了

[root@localhost ~]#grep 'temporary password' /var/log/mysqld.log

[root@master51 mha-soft-student]# mysql -uroot -p"N%;j+r!!s0pr"
可以使用临时密码第一次登陆 mysql
注:如果临时密码里有!这样的字符,就重新初始化数据库,换一个新的初始密码

 
第一次登陆进去后必须马上修改密码,不然下次登陆会报错。

mysql> show databases;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> set global validate_password_policy=0;       //只验证长度  
注:如果这里设置有误使用mysql> INSTALL PLUGIN validate_password SONAME 'validate_password.so';
参考:https://www.cnblogs.com/alonely/p/10927541.html

mysql> set global validate_password_length=6;      //修改密码长度,默认值是8个字符  注:感觉没用

mysql> alter user user()identified by"123456";     //修改登陆密码

查看密码验证策略
mysql> SHOW VARIABLES LIKE 'validate_password%';

上述操作的结果是——更改数据库用户root从本机访问时的密码,设为123456。

退出“mysql> ”环境,重新登录验证,必须采用新的密码才能登入:

[root@master51 mha-soft-student]# mysql -uroot -p"123456"
注:其他节点连接方式 >mysql -h 172.16.16.45 -P 3306 -uroot -p123
 
修改密码后:mysql>flush privileges;


五、设置所有机器都可以访问mysql服务
mysql> use mysql;   
mysql> GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
  这句话的意思 ,允许任何IP地址(上面的 % 就是这个意思)的电脑 用admin帐户  和密码(admin)来访问这个MySQL Server  

使配置生效
mysql>flush privileges;
 
查看版本
mysql> select version();
 
六、修改字符集
 修改前
 mysql> show variables like 'character_set_%';  
+--------------------------+----------------------------+  
| Variable_name            | Value                      |  
+--------------------------+----------------------------+  
| character_set_client     | latin1                     |  
| character_set_connection | latin1                     |  
| character_set_database   | latin1                     |  
| character_set_filesystem | binary                     |  
| character_set_results    | latin1                     |  
| character_set_server     | latin1                     |  
| character_set_system     | utf8                       |  
| character_sets_dir       | /usr/share/mysql/charsets/ |  
+--------------------------+----------------------------+  
 
 
vi /etc/my.cnf
 
[client]
default-character-set=utf8
 
[mysqld]
default-character-set=utf8
 
[mysql]
no-auto-rehash
default-character-set=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/ |
+--------------------------+----------------------------+
 
创建数据库(一定要在修改字符集后在创建数据库,否则字符集不对)
 
mysql> create database example;

 
七、客户端问题:
问题:
使用Navicat Premium客户端执行语句成功后总出现如下报错
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by


解决方案:
select version(),@@sql_mode;
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

标签:26,set,单机,el6,mysql5.7,5.7,character,mysql,rpm
来源: https://www.cnblogs.com/yclh/p/14951314.html