در ابتدا، شما در قبل از localhost از پد کاراکتر اشتباه استفاده کردید.
جای این:
فکر کنم دستور صحیح به این ترتیب هست:کد:create user ‘newuser1’@’localhost’ identified by ‘password1’;
کد:create user ‘newuser1’@‘localhost’ identified by ‘password1’;
در مورد باقی موارد، من یک ترجمه از 2 تا آموزش مورد استفاده خودم میزارم براتون:
ورود به دیتابیس با حساب روت (برای SSH)
کد:mysql -u root -p
ایجاد دیتابیس:
اگر مشکل نباشد خروجی زیر را مشاهده میکنید:کد:create database codebox;
ایجاد نام کاربری و رمز عبور + سطح دسترسی به دیتابیس ایجاد شده:
کد:Query OK, 1 row affected (0.16 sec)
کد:grant all privileges on codebox.* to 'milad'@'localhost' identified by "PaSSwOrd";
اگر قبلا نام کاربری ایجاد شده و الان قصد ایجاد دسترسی دارید فقط:
کد:GRANT all privileges ON codebox.* TO milad@'localhost';
مشاهده میکنید که ما all privileges را در همین دستور اعمال کردیم، اگر قصد دادن دسترسی کامل هم نداشتید 2 دستور بالا را میتونید اینطور بزنید:
کد:GRANT SELECT, INSERT, DELETE ON codebox TO milad@'localhost' IDENTIFIED BY 'PaSSwOrd';
یا مثلا در صورت وجود حساب این:
کد:GRANT SELECT, INSERT, DELETE ON codebox TO milad@'localhost';
حالا اعمال دسترسی های کاربر با این دستور:
کد:flush privileges;
در صورت نیاز برای بررسی دسترسی های یک کاربر:
در جدول زیر فهرست شده سطوح مختلف دسترسی:کد:select * from mysql.user where User='milad';
Privilege Meaning ALL [PRIVILEGES] Sets all simple privileges except GRANT OPTION ALTER Enables use of ALTER TABLE CREATE Enables use of CREATE TABLE CREATE TEMPORARY TABLES Enables use of CREATE TEMPORARY TABLE DELETE Enables use of DELETE DROP Enables use of DROP TABLE EXECUTE Not implemented FILE Enables use of SELECT ... INTO OUTFILE and LOAD DATA INFILE INDEX Enables use of CREATE INDEX and DROP INDEX INSERT Enables use of INSERT LOCK TABLES Enables use of LOCK TABLES on tables for which you have the SELECT privilege PROCESS Enables the user to see all processes with SHOW PROCESSLIST REFERENCES Not implemented RELOAD Enables use of FLUSH REPLICATION CLIENT Enables the user to ask where slave or master servers are REPLICATION SLAVE Needed for replication slaves (to read binary log events from the master) SELECT Enables use of SELECT SHOW DATABASES SHOW DATABASES shows all databases SHUTDOWN Enables use of MySQLadmin shutdown SUPER Enables use of CHANGE MASTER, KILL, PURGE MASTER LOGS, and SET GLOBAL statements, the MySQLadmin debug command; allows you to connect (once) even if max_connections is reached UPDATE Enables use of UPDATE USAGE Synonym for privileges GRANT OPTION Enables privileges to be granted
در نهایت فراموش نکنید:
دقت کنید در دستورات بالا موارد زیر مثال بود:
کد:exit;
codebox برای نام دیتابیس
milad برای نام کاربری
PaSSwOrd برای رمز عبور
منابع:
Creating a MySQL database and user on Gandi AI via SSH - Welcome to Gandi's Online Documentation Wiki - Gandi Docs
HOWTO: GRANT privileges in MySQL