阿里云Ubuntu20.04 安装 MySQL8

1、删除mysql

#执行修复命令,并重新执行更新和升级,确保完整修复问题。
sudo apt --fix-broken install
sudo apt-get update
sudo apt-get upgrade
#删除mysql
sudo apt-get autoremove --purge mysql-server sudo apt-get remove mysql-common

# 卸载mysql:
1.sudo apt-get autoremove mysql* --purge
2.sudo apt-get remove mysql-server
3.sudo apt-get remove mysql-common

# 清理残留数据
sudo dpkg -l |grep mysql|awk '{print $2}' |sudo xargs dpkg -P
sudo rm -rf /etc/mysql/
sudo rm -rf /var/lib/mysql

# 检查是否删除完毕
whereis mysql
sudo find / -name mysql

2、清理残留数据

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P 

3、重新安装mysql

sudo apt-get update
sudo apt-get install mysql-server          //服务端
sudo apt-get install mysql-client          //客户端
sudo apt-get install libmysqlclient-dev    //程序编译时链接的库

4、登录

#关闭mysql服务,

net stop mysql
#启动mysql服务,
net start mysql
#登录
mysql -u root -p

5、修改密码

use mysql;

ALTER USER 'root'@'localhost' IDENTIFIED BY '你要修改的密码';

flush privileges;

 6、查看是否运行远程访问

select host,user,plugin from user;

mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | mysql_native_password |
| localhost | mysql.sys | mysql_native_password |
+-----------+------------------+-----------------------+
4 rows in set (0.01 sec)

7、设置root远程访问

 update user set host='%' where user ='root';

 8、刷新权限

FLUSH PRIVILEGES;

9、创建用户分配权限

#创建用户dev
CREATE USER `dev`@`%` IDENTIFIED BY 'mysql520_dev';
#授权
GRANT ALL ON *.* TO `dev`@`%` WITH GRANT OPTION;

mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | dev | caching_sha2_password |
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | mysql_native_password |
| localhost | mysql.sys | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.01 sec)

#发现用户dev的加密连接方式plugin不对,修改一下

ALTER USER 'dev'@'%' IDENTIFIED WITH mysql_native_password BY 'mysql520_dev';

mysql> ALTER USER 'dev'@'%' IDENTIFIED WITH mysql_native_password BY 'mysql520_dev';
Query OK, 0 rows affected (0.01 sec)


mysql> select host,user,plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | dev | mysql_native_password |
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | mysql_native_password |
| localhost | mysql.sys | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

#记得刷新一下权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

 10、修改本地监听地址

# 查看监听
netstat -an |grep 3306
# 前监听的是本地回环地址:tcp 0 0 127.0.0.1:3306  0.0.0.0:* LISTEN #远程客户端无法访问 
# 修改MySQL的本地监听地址
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

#修改bind-address 的值为 bind-address = 0.0.0.0保存退出。
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0
mysqlx-bind-address     = 127.0.0.1

# 重启mysql数据库
sudo service mysql restart

 

 21、Ubuntu20.04安装nginx

2.1、安装nginx
apt-get install nginx

2.2、查看nginx版本

# 进入目录
cd usr/sbin/
# 查看版本
nginx -v
# 查看nginx状态
ps -ef | grep nginx

2.3、启动  停止 Nginx服务

#启动Nginx服务
sudo /etc/init.d/nginx start
#停止Nginx服务
sudo /etc/init.d/nginx quit

#加载最新配置
sudo /etc/init.d/nginx reload
#
立即停止Nginx服务
sudo /etc/init.d/nginx stop

2.4、配置nacos代理

#去到配置文件/etc/nginx下
cd /etc/nginx
#使用配置文件/etc/nginx/nginx.conf启动
nginx -c /etc/nginx/nginx.conf

 2.5 ubuntu常用命令

若要停止使用这个端口的程序,使用kill +对应的pid

kill  -9 pid

还有一个比较好用的命令,查看**端口:

sudo netstat -lnp | grep ** 

查看端口号和运行程序:

netstat -atunp | more

查看进程所用端口:

netstat -tlnp|grep **

以使用该端口获取进程列表

sudo lsof -i:80
停止使用端口80 sudo fuser -k 80 / tcp的进程

 

posted @ 2021-11-17 16:34  天意天雨  阅读(311)  评论(0编辑  收藏  举报