mysql
2025/6/30小于 1 分钟约 169 字
授权访问
# 关闭远程连接,只能本地连接,也可以通过以下步骤操作:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'101.43.62.33' IDENTIFIED BY 'lJ3HEYRGuyPqknde' WITH GRANT OPTION;
flush privileges;
use mysql #选中mysql数据库
update user set host=’localhost’ where user=’root’; #将host设置为localhost表示只能本地连接mysql
flush privileges; #刷新权限表,使配置生效mysql shell
# 跑脚本
.\mysqlsh.exe --ssl-mode=PREFERRED -f .\mysqlsh.jsshell.connect({
host: 'host',
port: 3306,
user: 'user',
password: 'pass',
});
session.runSql('use db')
const result = session.runSql("SELECT name from sys_role");
const rows = result.fetchAll()
print(rows.length)
rows.forEach(item=>{
// 由于select 可能有 name、age、grade 所以是数组
println(item[0])
})
// 更新
session.runSql("UPDATE b SET value = ? WHERE id = ?", [value, id]);