linux上搭建mysql服务,Linux上搭建MySQL远程服务

1. 安装MySQL

对于Ubuntu,直接使用apt-get安装,如果是CentOS,则同理使用yum

apt-get install -y mysql-server

2. 修改密码

输入mysql命令,直接进入MySQL客户端控制台

root@localhost:~# mysql

更新密码

mysql> update mysql.user set password=password('yourpassword') where user='root';

mysql> flush privileges;

注意如果MySQL的版本是5.7.x以上的话,mysql.user表里面的password字段已经改名为authentication_string,所以update语句要改成:

mysql> update mysql.user set authentication_string=password('yourpassword') where user='root';

mysql> flush privileges;

这里yourpassword是想要设置的修改后的密码

3. 设置允许远程连接

3.1 修改配置文件

修改配置文件/etc/mysql/mysql.conf.d,允许远程访问

vim /etc/mysql/mysql.conf.d

将bind-address注视掉

#bind-address = 127.0.0.1

3.2 修改权限

输入mysql命令,直接进入MySQL客户端控制台

root@localhost:~# mysql

输入授权语句

grant all privileges on *.* to 'root'@'%' identified by 'yourpassword' with grant option

这里的yourpassword对应着密码

4 修改MySQL的监听端口

编辑配置文件/etc/mysql/mysql.conf.d,修改对应的port属性,改成自己想要的端口号

port = 3306

5 重启MySQL

执行以下命令重启MySQL

root@localhost:~# /etc/init.d/mysql restart

6 使用命令行客户端远程连接MySQL

执行以下命令并输入密码即可

root@localhost:~# mysql -h -u -P -p

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值