mysql安装使用

apt安装
sudo apt install mysql-server
常用配置

参考:mysql配置文件

[mysqld]
basedir             = /usr // 安装目录
socket              = /usr/local/mysql/data/mysql.sock // mysql客户端程序和服务器之间的本地通讯时使用的套接字文件
pid-file            = /usr/local/mysql/data/mysql.pid // pid文件所在目录
datadir             = /var/lib/mysql // 数据文件存放的目录
bind_address        = 127.0.0.1 // 绑定的IP地址
port                = 3306 // 监听端口号
skip-grant-tables   = 1 // 跳过权限认证
常用管理命令
  • mysql服务启停
#启动
sudo service mysql start
#停止
sudo service mysql stop
  • 检查服务状态
systemctl status mysql.service
sudo service mysql status
  • 新增用户
create user "username"@"host" identified by "password";
  //host="localhost"为本地登录用户,host="ip"为ip地址登录,host="%"为外网ip登录
create user 'test'@'localhost' identified by 'test';
create user 'test'@'192.168.1.2' identified by 'test';
create user 'test'@'%' identified by 'test';
  • 修改密码
 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
  • 删除用户
drop user 'username'@'host';
  • 授权
grant privileges on databasename.tablename to 'username'@'host' IDENTIFIED BY 'PASSWORD';
 /*授予用户通过外网IP对于该数据库的全部权限*/
grant all privileges on `test`.* to 'test'@'%' ;
/*授予用户在本地服务器对该数据库的全部权限*/
grant all privileges on `test`.* to 'test'@'localhost';   
grant select on test.* to 'user'@'localhost';  /*给予查询权限*/
grant insert on test.* to 'user'@'localhost'; /*添加插入权限*/
grant delete on test.* to 'user'@'localhost'; /*添加删除权限*/
grant update on test.* to 'user'@'localhost'; /*添加权限*/
flush privileges; /*刷新权限*/
  • 删除权限
revoke privileges on databasename.tablename from 'username'@'host';
revoke delete on test.* from 'user'@'localhost';
  • 查询权限
show grants;
常见问题

mysql 8.0 版本以上如何修改root密码

你可能感兴趣的:(mysql安装使用)