发布时间:2025-12-11 01:14:05 浏览次数:1
在Ubuntu中,默认情况下,只有最新版本的MySQL包含在APT软件包存储库中,要安装它,只需更新服务器上的包索引并安装默认包apt-get。
sudoapt-getupdate
1、安装mysql服务:
sudoaptinstallmysql-server-5.7
2、检查状态:
需要先安装net-tools
sudoaptinstallnet-toolssudonetstat-tap|grepmysql
3、注意查看mysql版本使用:
mysql-V
4、查看MySQL5.7默认账号和密码:
sudocat/etc/mysql/debian.cnf
sudomysql_secure_installation
配置项较多,如下所示:
#1VALIDATEPASSWORDPLUGINcanbeusedtotestpasswords...Pressy|YforYes,anyotherkeyforNo:N(我的选项)#2Pleasesetthepasswordforroothere...Newpassword:(输入密码)Re-enternewpassword:(重复输入)#3Bydefault,aMySQLinstallationhasananonymoususer,allowinganyonetologintoMySQLwithouthavingtohaveauseraccountcreatedforthem...Removeanonymoususers?(Pressy|YforYes,anyotherkeyforNo):N(我的选项)#4Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.Thisensuresthatsomeonecannotguessattherootpasswordfromthenetwork...Disallowrootloginremotely?(Pressy|YforYes,anyotherkeyforNo):N(我的选项)#5Bydefault,MySQLcomeswithadatabasenamed'test'thatanyonecanaccess...Removetestdatabaseandaccesstoit?(Pressy|YforYes,anyotherkeyforNo):N(我的选项)#6Reloadingtheprivilegetableswillensurethatallchangesmadesofarwilltakeeffectimmediately.Reloadprivilegetablesnow?(Pressy|YforYes,anyotherkeyforNo):Y(我的选项)
systemctlstatusmysql.service
显示如下结果说明mysql服务是正常的:
连接到Mysql:
sudomysql-uroot-p
1、查看用户:
mysql>selectuser,pluginfrommysql.user;
2、重置Root密码,修改认证方式:
mysql>updatemysql.usersetauthentication_string=PASSWORD('123456'),plugin='mysql_native_password'whereuser='root';mysql>flushprivileges;mysql>exit1、修改配置文件,注释掉bind-address = 127.0.0.1
sudovi/etc/mysql/mysql.conf.d/mysqld.cnf
2、保存退出,然后进入mysql服务
mysql-uroot-p
3、执行授权命令:
mysql>grantallON*.*toroot@'%'identifiedby'123456'withgrantoption;QueryOK,0rowsaffected,1warning(0.00sec)mysql>flushprivileges;QueryOK,0rowsaffected(0.00sec)mysql>exitBye
其中root@%,localhost就是本地访问,配置成%就是所有主机都可连接;第二个'123456'为你给新增权限用户设置的密码。
4、重启
sudo/etc/init.d/mysqlrestart
想安装MySQL 8.0或者重装MySQL 5.7的前提条件,可以先删除已有的。
1.删除 mysql:
sudoaptautoremove--purgemysql-server-*sudoaptremovemysql-serversudoaptautoremovemysql-serversudoaptremovemysql-common
2.清理残留数据
dpkg-l|grep^rc|awk'{print$2}'|sudoxargsdpkg-P可以到官网,选择系统点击跳转下载 Workbench。
也可以更新软件包索引并直接安装 MySQL Workbench 软件包:
sudoaptupdatesudoaptinstallmysql-workbench
启动 MySQL Workbench。
您可以通过键入mysql-workbench或单击 MySQL Workbench 图标 (Activities -> MySQL Workbench) 从命令行启动它。
当您第一次启动 MySQL Workbench 时,应出现如下窗口:
连接配置界面
要添加新连接,请单击 “MySQL Connections” 旁边带圆圈的加号⊕。
将打开一个新窗口 “Setup New Connection form”。在此示例中,我们将通过 SSH 连接到远程服务器。在“Connection name”字段中输入有意义的名称,然后Standard TCP/IP over SSH从“连接方法”下拉列表中进行选择。
在 “SSH Hostname”中,输入服务器的主机名或 IP 地址,然后输入 SSH 端口。
输入您的远程 “SSH Username”。对于身份验证,您可以使用用户密码或 SSH 密钥。
保留 “MySQL Hostname”字段的默认值 (127.0.0.1) 。
在“Username”和“Password”字段中输入远程数据库登录凭据。
完成后,单击“测试连接”按钮。
这里直接点击已有的连接:
配置完成后,在主界面选择数据库进行连接: