sudo apt-get install mysql-server-5.7 # 安装mysql
apt install net-tools #安装
开启端口:更多参考https://blog.csdn.net/bigdata_mining/article/details/80699180
- sudo ufw status #查看防火墙是否启动
- sudo ufw allow 3306/tcp #启动3306端口
mysql 授权远程登录数据库现在本机上登录后执行语句 在使用远程连接
sudo mysql use mysql; update user set authentication_string=PASSWORD("你的密码") where User='root'; update user set plugin="mysql_native_password"; flush privileges; quit;
update user set host = '%' where user = 'root';
刷新权限:flush privileges;
退出数据库:quit;
本地连接:mysql -h localhost -u root -p123.
use mysql
SELECT User,authentication_string,plugin,`Host`
FROM `user`;
修改配置文件
vim /etc/mysql/mysql.conf.d/mysqld.cnf
查看MySQL进程:ps -ef | grep mysql
检查MySQL的状态:sudo service mysql status
开启MySQL服务器:sudo service mysql start
关闭MySQL服务器:sudo service mysql stop
重启mysql服务:service mysql restart
卸载Mysql
sudo apt purge mysql-*
之后执行Y
Centos8 安装 mysql8.0
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
sudo yum localinstall mysql80-community-release-el8-1.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
sudo yum install mysql-community-server
sudo service mysqld start #启动mysql
systemctl status mysqld #查看mysql 状态
sudo service mysqld start #查看mysql 状态
sudo service mysqld stop #停止mysql
sudo grep 'temporary password' /var/log/mysqld.log #查看安装的默认root密码
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'RootPwd@123456'; # 修改root密码
update user set host ='%' where user='root'; # 开放远程登录 防火墙3306端口也要打开
select user,host,authentication_string from user;
linux 开放/关闭端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开放5672端口 firewall-cmd --zone=public --remove-port=3306/tcp --permanent #关闭5672端口 firewall-cmd --reload # 配置立即生效 firewall-cmd --zone=public --list-ports #查看防火墙所有开放的端口 systemctl stop firewalld.service #关闭防火墙 firewall-cmd --state #查看防火墙状态 netstat -lnpt #查看监听端口 netstat -lnpt |grep 3306 #检查端口被哪个进程占用 ps 64202 #查看进程信息 kill 64202 #中止进程 firewall-cmd --add-port=123/tcp --permanent #添加指定需要开放的端口 firewall-cmd --reload #重载入添加的端口 firewall-cmd --query-port=123/tcp #查询指定端口是否开启成功 firewall-cmd --permanent --remove-port=123/tcp #移除指定端口
MySQL 基础操作
mysql -hlocalhost -u root -p mysql -u root -p --进入mysql数据库(-h表示服务器名,localhost表示本地;-u为数据库用户名,root是mysql默认用户名;-p为密码) ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlpwd'; show databases; --显示数据库 CREATE DATABASE DB;--创建数据库 drop database DB; -- 删除数据库 查看表:explain uu; describe uu; desc uu; show columns from UU; 查看所有的表:show tables;
参考:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html