美文网首页
Ubuntu/麒麟系统安装mysql,并修改大小写不敏感

Ubuntu/麒麟系统安装mysql,并修改大小写不敏感

作者: flyinghat | 来源:发表于2020-11-28 09:35 被阅读0次

通过apt 安装MySQL

$ sudo apt-get update
$ sudo apt-get install mysql-server

Ubuntu/麒麟 修改大小写不敏感

如果需要修改大小写不敏感,则在此步进行修改。根据实际情况找到自己安装的配置文件,我安装的Mysql配置文件位置

$ cd /etc/mysql/mysql.conf.d  #打开此文件

打开 mysqld.cnf文件修改

$ sudo vi mysqld.cnf

远程访问配置,找到以下两行,并注释

#bind-address       = 127.0.0.1  # 取消绑定127.0.0.1
#mysqlx-bind-address    = 127.0.0.1  # 取消绑定127.0.0.1

[mysqld]下增加一行

lower_case_table_names=1  # 大小写不敏感

保存后执行

$ sudo  rm -rf /var/lib/mysql/ # 清除数据,如果有重要数据则需要备份
$ sudo chown mysql:mysql /var/lib/mysql  # 给数据存放文件夹赋mysql操作权限,如果/var/lib/mysql不存在则手动创建 
$ sudo mkdir /var/lib/mysql  # 如果/var/lib/mysql不存在则手动创建 ,存在则不执行此条命令
$ sudo mysqld --initialize --user=mysql --lower-case-table-names=1  # 执行mysql初始化

mysql初始化后密码会丢失,需要重新设置

$ tail /var/log/mysql/error.log
或者
$ cat  /var/log/mysql/error.log

在打开的内容中找到这么一句话:

 A temporary password is generated for root@localhost: l!+*V&yQd8pV

其中 l!+*V&yQd8pV就是新的密码,复制一下

配置初始化信息

$ sudo mysql_secure_installation
Securing the MySQL server deployment.

Enter password for user root:   # 此处粘贴或输入刚刚复制的密码

The existing password for the user account root has expired. Please set a new password.

New password:     # 输入新的mysql密码

Re-enter new password:   # 再次输入新的mysql密码

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y  # 是否启用强密码验证 

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0  # 选择三种强密码验证强度,0 低级 1 中等 2 强
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n  #是否修改root密码 ,上面已经输入新的密码了,不需要再修改了

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y # 是否删除匿名用户
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #是否禁止root远程登录
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y #是否删除test数据库
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #是否立即重载设置
Success.

All done! 


添加用户配置访问权限

$ sudo mysql -uroot -p  #进入mysql

mysql> create user 'test1'@'%' identified by '密码'; # %= 本地+远程连接,
#如果出现Your password does not satisfy the current policy requirements 则说明密码强度弱,因为上面配置了要检测密码强度,因此需要一个强壮的密码,大小写数字特殊符号组合的密码
mysql> GRANT ALL ON *.* TO `test1`@`%` WITH GRANT OPTION;
mysql> flush privileges; # 刷新
mysql> show variables like '%case%';  #查看大小写敏感是否设置成功
-------------------------------+-------+
| Variable_name                      | Value |
+------------------------------------+-------+
| lower_case_file_system             | OFF   |
| lower_case_table_names             | 1     |
| validate_password.mixed_case_count | 1     |
+------------------------------------+-------+
若出现 lower_case_table_names  1 则说明成功

开放防火墙端口

$ sudo ufw allow 3306/tcp

重启mysql

$ sudo service mysql restart # 重启
$ service mysql status #查看状态

查看系统日志

$ cat /var/log/syslog
$ mysqld –help  #检查,如果它报告配置有任何问题

卸载

$  sudo apt purge mysql-*
$  sudo rm -rf /etc/mysql/ /var/lib/mysql
$  sudo apt autoremove
$  sudo apt autoclean

相关文章

网友评论

      本文标题:Ubuntu/麒麟系统安装mysql,并修改大小写不敏感

      本文链接:https://www.haomeiwen.com/subject/icsxwktx.html