Ubuntu18安装MySQL
第一步:安装MySQL
sudo apt-get install mysql-server 无法通过apt安装,应该是兼容性问题
sudo apt install mysql-client 安装client端
sudo apt install libmysqlclient-dev 安装依赖
netstat -tap | grep mysql 查看是否运行(参数:-t=tcp,-a=all,-p=显示程序名称)
第二步:进入MySQL
1、登录,命令:mysql -u root -p
第一次安装是不需要密码登录的,前提是在root用户下登录,不然会报登录错误:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
别慌,使用以下命令:
切换到根用户:su xxx(根用户名)
再次输入:mysql -u root -p
再按enter键,跳过输入密码步骤
2、修改登录密码
//展示数据库
show databases;
//选择MySQL数据库
use mysql;
//修改root用户的密码和插件类型
update user set plugin=“mysql_native_password”,authentication_string=password(“123456”) where user=“root”;
//刷新权限
flush privileges;
//退出MySQL
qiut
再次重新登录
具体安装过程也可以参考这位大神的文章:https://blog.csdn.net/u010986776/article/details/79860418
删库重装操作:
重要的一点,先停止数据库,在重装。不然会报一些错误,让你搜断手。
首先 sudo service mysql stop
sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
sudo apt-get install mysql-server mysql-common
参考链接:https://blog.csdn.net/miao0967020148/article/details/80218170
安装的参考过程:
root@zlb:/home/root_zlb# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38-0ubuntu0.18.04.1 (Ubuntu)
Copyright © 2000, 2022, Oracle and/or its affiliates.
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> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
4 rows in set (0.00 sec)
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
±--------------------------+
| Tables_in_mysql |
±--------------------------+
| columns_priv |
| db |