安装
前往mysql官网,下载mysql apt源配置程序MySQL :: Download MySQL APT Repository ,使用dkpg -i
安装。然后使用apt update
更新源,最后使用apt install mysql-server
安装即可。
简单配置
debian环境下,mysql的配置目录在/etc/mysql/mysql.conf.d
下,通过vim /etc/mysql/mysql.conf.d/mysqld.cnf
编辑mysqld守护进程的配置。
例子:
1 | [mysqld] |
更多mysql系统变量请参考MySQL :: MySQL 8.0 Reference Manual :: 5.1.8 Server System Variables
修改root密码
mysql没有初始root密码,可以直接终端输入mysql进入数据库。
要设置root密码,可以在 终端 执行
1 | mysqladmin -uroot password 'password' |
如果要修改root密码,在 终端 执行
1 | mysqladmin -uroot -p'oldpassword' password 'newpassword' |
mysql用户增删改查
新建用户
新建一个名为test,密码为test的用户,@'localhost'
指该用户只能通过本地网络访问;
如果指定ip,则把localhost
改为*ip
*,多个ip的话就多执行几次,ip分别修改为指定的某几个ip;
如果允许其通过任何ip访问,则把localhost
改为%
,%代表通配符,也可以设置192.168.0.%
允许来自192.168.0.1~192.168.0.255的ip进行访问
1 | create user 'test'@'localhost' identified by 'test'; |
删除用户
1 | drop user test@localhost; |
更改密码
1 | alter user 'test'@'localhost' identified with caching_sha2_password by 'newpassword'; |
查看权限
1 | show grants for user; |
修改权限
授予用户test通过外网IP对数据库“testdb”的全部权限
1 | grant all privileges on 'testdb'.* to 'test'@'%' identified by 'password'; |
打赏