Ubuntu18.04 安装MySQL57
1.1安装:
首先智行下面3条命令:
安装MySQL服务:
sudo apt-get install mysql-server
安装客户端:
sudo apt install mysql-client
安装依赖包:
sudo apt install libmysqlclient-dev
检查安装状态:
sudo netstat -tap |grep mysql
1.2设置root密码:
MySQL在安装完成后普通用户不能进入MySQL,原因是:root的plugin被修改成了auth_socket,用面登陆的plugin应是:mysql_native_passwors,直接用root权限就不需要密码,登录后修改root密码和登录验证方式:
$
sudo
su
# mysql
mysql>
mysql>
select
user, plugin from mysql.user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | auth_socket |
| mysql.session | mysql_native_password |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
4 rows
in
set
(0.00 sec)
mysql> update mysql.user
set
authentication_string=PASSWORD(
'123456'
), plugin=
'mysql_native_password'
where user=
'root'
;
mysql> flush privileges;
mysql>
select
user, plugin from mysql.user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | mysql_native_password |
| mysql.session | mysql_native_password |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
+------------------+-----------------------+
mysql>
exit
Bye
# exit
$
sudo
/etc/init
.d
/mysql
restart
$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection
id
is 2
Server version: 5.7.22-0ubuntu18.04.1 (Ubuntu)
Copyright (c) 2000, 2018, 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>
1.3配置mysql远程登录:
#修改配置文件,并注释掉bind-address = 127.0.0.1
sudo vi /etc/mysql/mysql.conf.d/mysql.cnf
保存退出,然后进入mysql,执行授权命令:
$ mysql -uroot -p
mysql> grant all on *.* to root@
'%'
identified by
'123456'
with grant option; #其中123456是自己刚设置的登录密码,不要复制,否则登录密码是123456
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
exit
Bye
$
sudo
/etc/init
.d
/mysql
restart
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!