centos 安装MySQL及踩坑大小写敏感

1、准备工作

1.1 查询是否已安装MySQL相关配置,若安装移除,没安装忽略

[root@10 local]# yum list installed | grep mysql
[root@10 local]# yum -y remove mysql57-community-release.noarch

[root@10 local]#  yum list installed | grep mysql
mysql57-community-release.noarch        el7-8                          installed
[root@10 local]#  yum -y remove mysql57-community-release.noarch 

1.2、查看centos版本 --不知道版本的可以使用相关命令查询下

cat /etc/redhat-release #查看CentOS版本
cat /proc/version

[root@10 /]#  cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@10 /]#  cat /proc/version
Linux version 3.10.0-957.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Thu Nov 8 23:39:32 UTC 2018

2、安装MySQL

2.1、下载MySQL

[root@10 local]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

2.2、安装MySQL源

[root@10 local]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
根据提示 输入 Y

2.3、检查是否安装成功

[root@10 local]# yum repolist enabled | grep "mysql.-community."

[root@10 local]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64      MySQL Connectors Community            108
mysql-tools-community/x86_64           MySQL Tools Community                  90
mysql57-community/x86_64               MySQL 5.7 Community Server            347

2.4 安装MySQL

[root@10 local]# yum install mysql-community-server
根据安装提示 Is this ok 输入 y

[root@10 local]#  yum install mysql-community-server
 。。。。。。此处省略。。。。。

事务概要
=================================================================================================================================================================================================================================================
安装  3 软件包 (+2 依赖软件包)

总下载量:194 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.26-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY                                                      ]  0.0 B/s |  67 kB  --:--:-- ETA 
mysql-community-common-5.7.26-1.el7.x86_64.rpm 的公钥尚未安装
(1/5): mysql-community-common-5.7.26-1.el7.x86_64.rpm                                                                                                                                                                     | 274 kB  00:00:06     
(2/5): mysql-community-libs-5.7.26-1.el7.x86_64.rpm                                                                                                                                                                       | 2.2 MB  00:00:01     
(3/5): mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm                                                                                                                                                                | 2.0 MB  00:00:00     
(4/5): mysql-community-client-5.7.26-1.el7.x86_64.rpm                                                                                                                                                                     |  24 MB  00:00:28     
(5/5): mysql-community-server-5.7.26-1.el7.x86_64.rpm                                                                                                                                                                     | 166 MB  00:00:41     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                                                             3.9 MB/s | 194 MB  00:00:49     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥
导入 GPG key 0x5072E1F5:
 用户ID     : "MySQL Release Engineering "
 指纹       : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 软件包     : mysql57-community-release-el7-8.noarch (installed)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 。。。。。。此处省略。。。。。
已安装:
  mysql-community-libs.x86_64 0:5.7.26-1.el7                                   mysql-community-libs-compat.x86_64 0:5.7.26-1.el7                                   mysql-community-server.x86_64 0:5.7.26-1.el7                                  

作为依赖被安装:
  mysql-community-client.x86_64 0:5.7.26-1.el7                                                                            mysql-community-common.x86_64 0:5.7.26-1.el7                                                                           

替代:
  mariadb-libs.x86_64 1:5.5.60-1.el7_5                                                                                                                                                                                                           

完毕!
[root@10 local]# 

2.5 启动MySQL并查询启动状态

启动MySQL
[root@10 local]# systemctl start mysqld
查询启动状态
[root@10 local]# systemctl status mysqld

[root@10 local]# systemctl start mysqld
[root@10 local]#  systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2019-05-31 10:01:34 CST; 1min 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 4539 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 4466 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 4542 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─4542 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

5月 31 10:01:30 10.0.2.15 systemd[1]: Starting MySQL Server...
5月 31 10:01:34 10.0.2.15 systemd[1]: Started MySQL Server.

可以看到 服务已经正常启动

2.6 、 设置开机启动

[root@10 local]# systemctl enable mysqld
[root@10 local]# systemctl daemon-reload

[root@10 local]# systemctl enable mysqld
[root@10 local]# systemctl daemon-reload

2.7、MySQL修改root密码

MySQL安装完成之后  在var/log/mysqld.log 生成默认密码  ,可以使用cat命令查询密码

[root@10 local]# cat /var/log/mysqld.log
如下 密码位置 A temporary password is generated for root@localhost: Q+Cl2sDfnhOf

[root@10 local]# cat /var/log/mysqld.log
2019-05-31T02:01:30.489346Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-31T02:01:31.136488Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-05-31T02:01:31.258342Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-05-31T02:01:31.314779Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 026dd721-8348-11e9-8b9f-0800272dc669.
2019-05-31T02:01:31.315398Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-05-31T02:01:31.315835Z 1 [Note] A temporary password is generated for root@localhost: Q+Cl2sDfnhOf
2019-05-31T02:01:34.105853Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-31T02:01:34.106981Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.26) starting as process 4542 ...
2019-05-31T02:01:34.121691Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-05-31T02:01:34.121923Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-05-31T02:01:34.121963Z 0 [Note] InnoDB: Uses event mutexes
2019-05-31T02:01:34.121968Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-05-31T02:01:34.121972Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-05-31T02:01:34.121976Z 0 [Note] InnoDB: Using Linux native AIO
2019-05-31T02:01:34.122231Z 0 [Note] InnoDB: Number of pools: 1
2019-05-31T02:01:34.122313Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-05-31T02:01:34.123694Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-05-31T02:01:34.137848Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-05-31T02:01:34.140811Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-05-31T02:01:34.153257Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2019-05-31T02:01:34.159667Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-05-31T02:01:34.159740Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-05-31T02:01:34.280067Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-05-31T02:01:34.280872Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-05-31T02:01:34.280880Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2019-05-31T02:01:34.281002Z 0 [Note] InnoDB: Waiting for purge to start
2019-05-31T02:01:34.332651Z 0 [Note] InnoDB: 5.7.26 started; log sequence number 2525131
2019-05-31T02:01:34.333222Z 0 [Note] Plugin 'FEDERATED' is disabled.
2019-05-31T02:01:34.341944Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-05-31T02:01:34.344914Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190531 10:01:34
2019-05-31T02:01:34.348719Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2019-05-31T02:01:34.349255Z 0 [Warning] CA certificate ca.pem is self signed.
2019-05-31T02:01:34.368394Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2019-05-31T02:01:34.368553Z 0 [Note] IPv6 is available.
2019-05-31T02:01:34.368563Z 0 [Note]   - '::' resolves to '::';
2019-05-31T02:01:34.368581Z 0 [Note] Server socket created on IP: '::'.
2019-05-31T02:01:34.377423Z 0 [Note] Event Scheduler: Loaded 0 events
2019-05-31T02:01:34.377516Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.26'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

也可以使用命名直接查询文件查找root 密码所在行

[root@10 local]# grep 'temporary password' /var/log/mysqld.log

[root@10 local]# grep 'temporary password' /var/log/mysqld.log
2019-05-31T02:01:31.315835Z 1 [Note] A temporary password is generated for root@localhost: Q+Cl2sDfnhOf

PS 密码就是 Q+Cl2sDfnhOf

修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password01!';
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678'; 
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password01!';
Query OK, 0 rows affected (0.00 sec)

2.8、添加远程登录用户

默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户

添加用户 test 密码Testuser01!
GRANT ALL PRIVILEGES ON . TO 'test'@'%' IDENTIFIED BY 'Testuser01!' WITH GRANT OPTION;

mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' IDENTIFIED BY 'Testuser01!' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

2.9、MySQL通过改配置设置区分大小写 --- 不要试了 反正我没有成功

不知道为什么 我这儿安装 MySQL居然不区分大小写。。。
只能自己设置了 先退出 MySQL界面
mysql> exit

进入配置编辑 vim /etc/my.cnf

[root@10 local]# vim /etc/my.cnf

输入 i 进入编辑模式 编辑完成后 按esc 退出编辑模式,输入 :wq 保存退出

#解决中文乱码问题

character_set_server=utf8

#设置字段值区分大小写、

collation_server=utf8_bin

#设置表名不区分大小写(0:敏感)

lower_case_table_names=1

centos 安装MySQL及踩坑大小写敏感_第1张图片
image.png

MySQL重启
[root@10 local]# systemctl restart mysqld

2.10、MySQL建表时设置区分大小写 通过 BINARY 字段

DROP TABLE IF EXISTS su_user;
CREATE TABLE su_user (
user_id varchar(6) NOT NULL COMMENT '用户ID',
login_name varchar(10) BINARY NOT NULL COMMENT '登录名'
modifyTime datetime NOT NULL COMMENT '操作时间',
PRIMARY KEY (user_id),
KEY FK_user_organ (org_id),
CONSTRAINT FK_user_organ FOREIGN KEY (org_id) REFERENCES dt_organ (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

2.10、MySQL查询时设置区分大小写 通过 BINARY 字段

SELECT * FROM su_user WHERE BINARY login_name = 'admin'

-----end---

你可能感兴趣的:(centos 安装MySQL及踩坑大小写敏感)