阿里云Centos使用自带mysql

---查看、设置服务(以firewalld服务为例)
从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig

启动一个服务: systemctl start firewalld.service
关闭一个服务: systemctl stop firewalld.service
重启一个服务: systemctl restart firewalld.service

显示一个服务的状态: systemctl status firewalld.service
在开机时启用一个服务: systemctl enable firewalld.service
在开机时禁用一个服务: systemctl disable firewalld.service

查看服务是否开机启动: systemctl is-enabled firewalld.service;echo $?
查看已启动的服务列表: systemctl list-unit-files|grep enabled


----------------------------------------------------- 阿里云 centos 使用 mysql ----------------------------------------------------
阿里云centos自带mysql    https://blog.csdn.net/IT_faquir/article/details/75195118?locationNum=2&fps=1

安装目录 /usr/local/mysql
版本: 5.7.22
监听端口:3306
配置文件: /etc/my.cnf
数据文件: /usr/local/mysql/data
默认密码: uAiqwVwjJ8-i
命令: systemctl (start|stop|restart|disable) mysql
示例: 启动mysql systemctl start mysql
重启mysql systemctl restart mysql
禁止mysql systemctl disable mysql



0.关闭防火墙、阿里云ECS设置安全组进出方向放行(3306/3306、8080/8080)
https://blog.csdn.net/java_raylu/article/details/73196737
https://www.linuxidc.com/Linux/2016-12/138979.htm

-防火墙:CentOS 7.0默认使用的是firewall作为防火墙(iptables ?)
firewall-cmd --state 查看防火墙状态
systemctl start firewalld.service 开启防火墙
systemctl stop firewalld.service 关闭firewall
systemctl disable firewalld.service 禁止firewall开机启动

-安全组设置:看看阿里云官网

1.开启mysql服务
service mysql start; 开启服务 (服务名就是叫mysql,不是mysqld ?)
service mysql stop; 停止服务
service mysql restart; 重启服务

2.忘记mysql密码,重置密码  (查看/root/readme.txt 或者:)
https://blog.csdn.net/return111/article/details/72802341 (手动修改配置文件)
https://blog.csdn.net/zbbzb/article/details/79379779 (命令修改配置文件,修改密码的命令好像用不了)

-更改配置文件(需重启mysql服务),跳过mysql密码检查,登录成功后更改密码。

sed -i '/mysqld/a\skip-grant-tables' /etc/my.cnf 修改mysql配置文件(位于 /etc/)
service mysql restart 重启mysql服务
mysql -u root -p 跳过密码输入登录mysql;遇到密码输入直接回车
mysql>use mysql 选择mysql数据库
mysql>update mysql.user set authentication_string=password('123456') where user='root'; 修改root用户登录密码为123456
mysql>flush privileges;
mysql>quit; 保存更改
sed -i 's/skip-grant-tables/#skip-grant-tables/g' /etc/my.cnf 配置文件修改为原来的设置
service mysql restart; 重启mysql,ok,使用新密码登录root即可。

3.设置mysql可远程访问
https://blog.csdn.net/java_raylu/article/details/73196737
-方法一:授权;
mysql -u root -p //输入密码,登录MySQL
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; //授权任何远程主机都可以访问数据库
mysql> FLUSH PRIVILEGES; //需要输入次命令使修改生效
mysql> quit; //退出

-方法二:修改表;
mysql -u root -p
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> quit;

4.mysql导入sql文件
https://www.cnblogs.com/walblog/articles/7890442.html
-sql文件名与数据库名字一致;没有该数据库则先建数据库再执行sql;
mysql -u root -p 输入密码,进入mysql数据库
mysql>create database Student; 新建一个和文件相同名字的数据库Student
mysql> use Student; 切换到该数据库
mysql>set names utf8; 设置编码
mysql>source /Student.sql; 导入位于根目录的sql文件,ok。

猜你喜欢

转载自www.cnblogs.com/badboyh2o/p/9575722.html