程序员开发实例大全宝库

网站首页 > 编程文章 正文

Ubuntu18.04上安装MySQL(ubuntu18.04上安装testbed)

zazugpt 2024-10-23 16:53:53 编程文章 21 ℃ 0 评论

前言:

作者在Ubuntu上安装MYSQL出现了一下问题,如何解决呢?

1、打开终端取得root权限

sudo su

2、在终端输入:

sudo apt-get install mysql-server
sudo apt-get install mysql-client 
sudo apt-get install libmysqlclient-dev
  • 安装的过程中,基本都是输入y进行下载
  • 安装完成之后输入 netstat -tap | grep mysql
  • 显示mysql代表安装成功

3、修改配置

Ubuntu的终端输入sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 进入配置文件

为了可以远程注释: bind-address = 127.0.0.1

在配置文件中的[mysqld]这一块中加入skip-grant-tables

加入之后可以让你不用密码登录mysql,保存后退出

输入 sudo service mysql start 重启 MySQL

4、输入mysql -uroot -p 进入mysql

提示输入密码直接回车就可以了

输入use mysql;

后再输入select user,plugin from user;

mysql> select user,plugin from user;
+------------------+-----------------------+
| user ? ? ? ? ? ? | plugin ? ? ? ? ? ? ?  |
+------------------+-----------------------+
| root ? ? ? ? ? ? | auth_socket ? ? ? ? ? |
| mysql.session ?  | mysql_native_password |
| mysql.sys ? ? ?  | mysql_native_password |
| debian-sys-maint | mysql_native_password |
| phpmyadmin ? ? ? | mysql_native_password |
+------------------+-----------------------+
5 rows in set (0.00 sec)

发现和上面一样后输入update user set authentication_string=password('密码'),plugin='mysql_native_password' where user='root';

完成后

输入 select user,plugin from user; 与下面一样就可以了

mysql> select user,plugin from user;
+------------------+-----------------------+
| user ? ? ? ? ? ? | plugin ? ? ? ? ? ? ?  |
+------------------+-----------------------+
| root ? ? ? ? ? ? | mysql_native_password |
| mysql.session ?  | mysql_native_password |
| mysql.sys ? ? ?  | mysql_native_password |
| debian-sys-maint | mysql_native_password |
| phpmyadmin ? ? ? | mysql_native_password |
+------------------+-----------------------+
5 rows in set (0.00 sec)

让本机访问虚拟机MYSQL还需要授权

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;

flush privileges;

Ubuntu的终端输入sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 进入配置文件,注释: skip-grant-tables 保存退出

sudo service mysql start 重启MySQL

5、如何卸载MYSQL

首先在终端中查看MySQL的依赖项:dpkg --list|grep mysql

卸载: sudo apt-get remove mysql-common

卸载:sudo apt-get autoremove --purge mysql-server-5.7

清除残留数据:dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P

再次查看MySQL的剩余依赖项:dpkg --list|grep mysql

部分命令来源于网络。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表