用root用户登陆mysql开发工具(建议 MySql Workbench),在SQL执行窗口执行下面sql,会创建一个test_db的数据库:
DROP DATABASE IF EXISTS test_db; -- 建立数据库 CREATE DATABASE IF NOT EXISTS test_db DEFAULT CHARSET utf8 COLLATE utf8_general_ci; -- 设置全UTF-8访问 alter database test_db character set utf8; set character_set_client=utf8; set character_set_connection=utf8; set character_set_database=utf8; set character_set_results=utf8; set character_set_server=utf8; -- 建立用户,授全部权限给test_user用户 -- 设置test_user可以通过localhost访问数据库 GRANT ALL PRIVILEGES ON test_user.* TO ‘test_db‘@‘%‘ IDENTIFIED BY ‘test_password‘ WITH GRANT OPTION; -- 设置test_user可以远程访问数据库 GRANT ALL PRIVILEGES ON test_user.* TO ‘test_db‘@‘localhost‘ IDENTIFIED BY ‘test_password‘ WITH GRANT OPTION; -- 刷新权限 FLUSH PRIVILEGES;
时间: 2025-01-06 22:05:57