Mysql 简单操作(腾讯云)

一、远程\帐号\配置

1) 、开启远程连接

  • 默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件。
  • 修改/etc/mysql/my.conf
    找到bind-address = 127.0.0.1这一行
    改为bind-address = 0.0.0.0即可

2) 、为需要远程登录的用户赋予权限

  • 1、新建用户远程连接mysql数据库
grant all on *.* to root@'%' identified by 'dbnwd123' with grant option; 
flush privileges;

允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。
注意admin账户不一定要存在。


  • 2、支持root用户允许远程连接mysql数据库
    grant all privileges on . to ‘root’@’%’ identified by ‘123456’ with grant option;
    (%表示是所有的外部机器,如果指定某一台机,就将%改为相应的机器名;‘root’则是指要使用的用户名,)
    flush privileges;(运行此句才生效,或者重启MySQL)

  • 3、撤销授权(这不是步骤之一,只是记录下命令)

  mysql> revoke all privileges on *.* from 'cuihe'@'%';
  • 4、查看权限
    https://www.cnblogs.com/gengsc/p/6905536.html

show grants for root@’%’;
在这里插入图片描述


  • 5、设置远程访问权限方法总结
    https://www.cnblogs.com/jielite/p/3693266.html

设置访问单个数据库权限:

  mysql>grant all privileges on test.* to 'root'@'%';

3) 、修改密码

  • 修改密码

    进入mysql :

   mysql -uroot -p ;
  • 修改密码(修改密码为:123456)
update mysql.user set authentication_string=password('123456') where user='root'

4) 、重启mysql

   service mysql restart

5) 、设置数据库最大连接数

 mysql -uroot -p ;
 
 show global status like 'Max_used_connections';
 set GLOBAL max_connections=1024;
 show variables like '%max_connections%';

https://www.cnblogs.com/phpper/p/9570792.html


二、表操作

1. 创建数据库

mysql> create database if not EXISTS  nwdcloud
    -> default character set utf8mb4
    -> default COLLATE utf8mb4_general_ci;

2. 清空数据表

use xxdbname;
TRUNCATE table xxxx

猜你喜欢

转载自blog.csdn.net/oZiJing/article/details/119207517