CentOS7下安装mysql5.7

3、获取安装时的临时密码(在第一次登录时就是用这个密码):

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2020-09-11T08:25:45.858187Z 1 [Note] A temporary password is generated for root@localhost: 3MsZD2eq0r&r
[root@localhost ~]# mysql -uroot -p3MsZD2eq0r&r
[1] 2200
-bash: r: command not found
[root@localhost ~]# mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[1]+  Exit 1                  mysql -uroot -p3MsZD2eq0r
[root@localhost ~]# mysql -uroot -p'3MsZD2eq0r&r'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.31

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

密码有特殊符号,加上单引号。

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

第一次访问必须修改密码;

Mysql5.7第一次修改密码

参考文章:https://blog.csdn.net/weixin_42182501/article/details/88766211
以下为博文内容:

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

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

[root@master51 mha-soft-student]# mysql -uroot -p"kqjSmtYn7i>Y"
可以使用临时密码第一次登陆 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> set global validate_password_length=6;      //修改密码长度,默认值是8个字符

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

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

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

根据实际操作,发现5.7的密码已经很严格了。执行以下设置密码:

mysql> alter user user()identified by "1qaz@WSX";
Query OK, 0 rows affected (0.00 sec)

设置远程机器访问

user mysql;
mysql> select host,user from user;
±----------±--------------+
| host | user |
±----------±--------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
±----------±--------------+
3 rows in set (0.00 sec)

mysql> update user set host=’%’ where user=‘root’;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Mysql操作命令

启动和停止服务

systemctl restart mysqld
systemctl stop mysqld
systemctl start mysqld

开启3306端口:

[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --query-port=3306/tcp
no
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --query-port=3306/tcp
yes
[root@localhost ~]# 

设置大小写敏感

linux下mysql设置大小写不敏感

1、linux下mysql安装完后是默认:区分表名的大小写,不区分列名的大小写;

2、用root帐号登录后,在/etc/my.cnf 中的[mysqld]后添加添加

lower_case_table_names=1

重启MYSQL服务,这时已设置成功:不区分表名的大小写;
lower_case_table_names参数详解:

lower_case_table_names = 0

其中 0:区分大小写,1:不区分大小写
MySQL在Linux下数据库名、表名、列名、别名大小写规则是这样的:
   1、数据库名与表名是严格区分大小写的;
   2、表的别名是严格区分大小写的;
   3、列名与列的别名在所有的情况下均是忽略大小写的;

4、变量名也是严格区分大小写的;

MySQL在Windows下都不区分大小写。
3、如果想在查询时区分字段值的大小写,则:字段值需要设置BINARY属性,设置的方法有多种:
A、创建时设置:

CREATE TABLE T( A VARCHAR(10) BINARY );

B、使用alter修改:

ALTER TABLE tablename MODIFY COLUMN cloname VARCHAR(45) BINARY;

C、mysql table editor中直接勾选BINARY项。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值