2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
- // linux 使用yum安装或者rpm安装。(就是一个安装工具类似于applStore,brew不必在意)
- // 区别:yum会自动安装你要安装的东西的其他依赖,rpm不会但会提示你需要安装的东西,比较麻烦,所以采用yum安装
- yum list installed mysql*
- rpm -qa|grep mysql*
- // 两个都查询一下,看一下是哪个工具installed,就用哪个工具卸载,防止rpm卸载不干净
-
- // 对应的卸载命令
- yum remove mysql
- rpm -e mysql
-
-
- // yum 查看一下 仓库中有哪些mysql版本,一般只会有最新版
- yum info mysql
-
- // 采用yum安装,直接安装mysql server服务,比较纯净的安装,傻等就安装好了。
- yum install mysql-server
- // 启动mysql或者退出mysql server
- service mysqld start
- service mysqld stop
-
- // 查询是否启动。进程查看/端口是否监听
- netstat -lnp|grep 3306 // 3306端口是否启动
- ps -ef|grep mysql // 是否有mysql进程
Use the following command to disable GPG
yum -y install mysql-community-server --nogpgcheck
The installation is complete
Click on this security group, enter the configuration rules, select the inbound direction, manually add, add port 3306, and thenRestart the server, restart mysql, so that you can access mysql from the external network.
After installing MySQL, the system will generate a temporary password. You can find this temporary password in the MySQL log file. Run the following command:
grep 'temporary password' /var/log/mysqld.log
Log in to MySQL using the temporary password
mysql -u root -p
After successful login, reset the root user's password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword!';
mysql open remote permissions
- #登录mysql
- mysql -u root -p;
- #选择mysql数据库
- use mysql;
- #查看user表
- select host, user, authentication_string, plugin from user;
As shown in the figure below, if the host of the root user is "localhost", it indicates that only local access is allowed;
"%" means granting the root user all permissions from any host
Related commands:
If it is a version before MySQL 8.0
- #进入MySQL数据库后进入MySQL数据库。
- mysql -u root -p;
- #切换到mysql数据库。
- mysql> use mysql;
- #授予root用户从任何主机中的所有权限,并设置密码。
- mysql> grant all privileges on *.* to 'root'@'%' identified by 'root用户密码' with grant option;
- #刷新权限
- mysql> flush privileges;
MySQL version 8.0 or later
- #进入MySQL数据库后进入MySQL数据库。
- mysql -u root -p ;
- #将root用户的主机设置为任意主机
- mysql> update user set host = '%' where user = 'root';
- #刷新权限
- mysql> flush privileges;
This method is a detour method. Without configuring any MySQL, first useSSH connectionAlibaba Cloud server, and then use localhost to connect to the MySQL database.
Click SSH first
Click General Connections
The above connection is successful!