当前位置: 首页 > news >正文

KylinV10 安装 MySQL 教程(可防踩雷)

KylinV10 安装 MySQL 教程(可防踩雷)

1、直接用 apt 快捷安装 MySQL

$ sudo apt-get update #更新软件源
$ sudo apt-get install mysql-server #安装mysql

然后你会发现,KylinV10 安装畅通无阻,并没有设置密码的场景,于是你一登陆,发现有密码(?哪来的密码)

kylin@kylinV10:~/桌面$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
kylin@kylinV10:~/桌面$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

2、KylinV10 密码正确也无法登录的情况

这里有点问题的是,银河麒麟系统有点不同,按网上一些改密码的教程,会发现,密码该成功了,输入密码正确也无法登录,输入密码半天连接不了,也不知道是当时设置密码的时候打错了,两次都打错不应该啊。

1703062515988

其实这里主要原因就是因为 kylinV10 的加密方式不一样,MySQL 一般是 mysql_native_password 认证方式,但是 kylinV10 的认证方式是 auth_socket。所以要先改这个,接下来教大家如何改!

1703062674335

3、修改认证方式步骤

具体操作如下:

1、在 mysqld.cnf 最后一行里添加 skip-grant-tables

# 使用 gedit 或者 vim 命令都可以(二选一即可)
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
# 使用 vim 命令
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

直接在最后一行添加

skip-grant-tables
# 如下图

1703062962414

保存后,退出,不用去管报什么错误警告,比如下图这样的

在这里插入图片描述

2、重启 MySQL

sudo service mysql restart

3、连接 MySQL

# 只需要输入mysql就行,其他不用
mysql

4、切换到 mysql 数据库

use mysql;

5、查看一下加密方式

select user, plugin from user;
1703062674335

如果是如图 auth_socket 需要将其修改为 mysql_native_password 这就是为什么我改了几次密码,都还是无法连接成功的原因:身份验证的插件是错的。

6、修改加密认证方式

update user set plugin='mysql_native_password' where user='root';
flush privileges;

7、修改密码

ALTER user 'root'@'localhost' IDENTIFIED BY '123456'; //123456是新密码,改成你自己的
# 注意 MySQL8.0是不支持 password() 函数的,所以以下命令是无效的 
# 如果你安装的是MySQL5.x可以执行下面命令
update user set authentication_string=password("123456"),plugin='mysql_native_password' where user='root';

8、退出

exit;

9、去掉 skip-grant-tables 重启 MySQL 服务

sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
# 可以选择删除或者注释掉,注释的话在前面加个 # 就行了

10、重启 MySQL 服务

sudo service mysql restart

11、完整的过程图

1703063339930

4、还不行?还有招

1、初始化配置,设置密码

sudo mysql_secure_installation

然后下面步骤有点多,注意认真看

# 1
Securing the MySQL server deployment.Connecting to MySQL using a blank password.VALIDATE PASSWORD PLUGIN 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 plugin?
# 这里我选择了 No
Press y|Y for Yes, any other key for No: No
# 2
Please set the password for root here...New password: (输入密码)Re-enter new password: (重复输入)
# 3
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.
# 我选择了 No
Remove anonymous users? (Press y|Y for Yes, any other key for No) : No 
# 4
Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network...
# 我选择了 Yes
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Yes
#5By default, MySQL comes with a database named 'test' thatanyone can access...
# 我选择了 No
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : No
#6Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.
# 我选择了 Yes
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Yes

2、检查MySQL状态

systemctl status mysql.service

3、在终端连接

mysql -u root -p;# 输入密码

5、sqoop 导入 MySQL 中文乱码问题

(可以插入中文,但不能用sqoop导入中文)导致导入时中文乱码的原因是character_set_server默认设置是latin1

可以单个设置修改编码方式set character_set_server=utf8;但是重启会失效,建议按以下方式修改编码方式。

(1)编辑配置文件。

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 或者
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf

(2)在[mysqld]下添加一行

character_set_server=utf8

在这里插入图片描述

(3)重启MySQL服务。

service mysql restart

(4)查看character_set_server设置

show variables like "char%";
# 如下图,可以看到 character_set_server 已经变成了 utf8 了

64529576.webp" alt=“1703064529576” style=“zoom: 50%;” />

(3)重启MySQL服务。

service mysql restart

(4)查看character_set_server设置

show variables like "char%";
# 如下图,可以看到 character_set_server 已经变成了 utf8 了

在这里插入图片描述

相关文章:

  • 2023前端面试题(计算机网络):HTTP和HTTPS协议的区别
  • CJson 使用 - 解析Object结构
  • 计算机图形学理论(3):着色器编程
  • 【iOS】UICollectionView
  • 双向长短期记忆网络(Bi-LSTM)-多输入回归预测
  • P4 音频知识点——PCM音频原始数据
  • ChatGPT4与ArcGIS Pro3助力AI 地理空间分析和可视化及助力科研论文写作
  • Ionic实战二十七:移动端录音方案及Nginx部署配置
  • ubuntu22上使用qemu-system-arm调试linux
  • DLLNotFoundException:xxx tolua... 错误打印
  • ubuntu22.04+ROS2推荐匹配的gazebo版本
  • LeetCode 每日一题 2023/12/18-2023/12/24
  • python 使用 pip 安装第三方库 导入不成功
  • 【算法设计与分析】——动态规划算法
  • 【docker笔记】docker常用命令
  • 收藏网友的 源程序下载网
  • Android Studio:GIT提交项目到远程仓库
  • Angular数据绑定机制
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • Fundebug计费标准解释:事件数是如何定义的?
  • HTTP传输编码增加了传输量,只为解决这一个问题 | 实用 HTTP
  • in typeof instanceof ===这些运算符有什么作用
  • k8s 面向应用开发者的基础命令
  • Linux gpio口使用方法
  • Netty 4.1 源代码学习:线程模型
  • Xmanager 远程桌面 CentOS 7
  • 创建一种深思熟虑的文化
  • 反思总结然后整装待发
  • 个人博客开发系列:评论功能之GitHub账号OAuth授权
  • 前端每日实战 2018 年 7 月份项目汇总(共 29 个项目)
  • 使用agvtool更改app version/build
  • 微信小程序开发问题汇总
  • 一文看透浏览器架构
  • 以太坊客户端Geth命令参数详解
  • 用Canvas画一棵二叉树
  • 用Visual Studio开发以太坊智能合约
  • 云大使推广中的常见热门问题
  • ​七周四次课(5月9日)iptables filter表案例、iptables nat表应用
  • ​虚拟化系列介绍(十)
  • ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTr
  • #mysql 8.0 踩坑日记
  • (007)XHTML文档之标题——h1~h6
  • (1/2)敏捷实践指南 Agile Practice Guide ([美] Project Management institute 著)
  • (4) PIVOT 和 UPIVOT 的使用
  • (C++17) optional的使用
  • (第27天)Oracle 数据泵转换分区表
  • (定时器/计数器)中断系统(详解与使用)
  • (附源码)springboot掌上博客系统 毕业设计063131
  • (机器学习-深度学习快速入门)第一章第一节:Python环境和数据分析
  • (小白学Java)Java简介和基本配置
  • (一)kafka实战——kafka源码编译启动
  • (转)ORM
  • .NET 8.0 中有哪些新的变化?
  • .NET 材料检测系统崩溃分析
  • .net 前台table如何加一列下拉框_如何用Word编辑参考文献