Centos7下安装mysql

来源:互联网 发布:淘宝网上买的300元的狗 编辑:程序博客网 时间:2024/04/30 10:56
1将虚拟机的网络模式改为桥接模式,重启虚拟机,将连接改为自动获取ip。(只要虚拟机可以上网即可)
2 下载mysql的repo资源
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
3 安装mysql-community-release-el7-5.noarch.rpm包
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
4 安装mysql
$ sudo yum install mysql-server
5 启动mysql
$ service mysqld start
6登陆,修改密码
首次登陆不需密码 $ mysql -u root
mysql > use mysql;mysql > update user set password=password(‘root‘) where user=‘root‘;mysql > exit;
7 开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
success后,执行$ firewall-cmd --reload
( systemctl stop firewalld.service #停止
systemctl disable firewalld.service #禁用)

8 mysql安装后还要允许远程连接,其他服务器才能连接到本地的数据库。
mysql -u root -p //登录MySQL
mysql账户是否不允许远程连接。如果无法连接可以尝试以下方法:
mysql -u root -p //登录MySQL
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; //任何远程主机
都可以访问数据库
注意: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; //任何远程主机都可以root账户访问数据库
mysql> FLUSH PRIVILEGES; //需要输入次命令使修改生效
mysql> EXIT //退出
0 0
原创粉丝点击