Hướng dẫn can not create database in mysql? - không thể tạo cơ sở dữ liệu trong mysql?

Tôi đang sử dụng Mac OS X Lion và vừa cài đặt MySQL5 bằng MacPorts.

Sau đó, tôi đã chạy thành công:

sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql

Tôi có thể khởi động máy chủ và kết nối là 'root' tốt, nhưng tôi không thể tạo bất kỳ cơ sở dữ liệu nào.

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'

Tôi đã thực hiện rất nhiều googling khi cố gắng tìm ra điều này và có vẻ như vấn đề có thể phải làm với các quyền hệ thống tệp cho/opt/local/var/db/mysql5, nhưng tôi đã thử thay đổi những điều này :

$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx  8 _mysql  _mysql  272 Apr 12 11:55 mysql5

Tôi đã thử nghiệm với chủ sở hữu là '_mysql', 'mysql' và 'root: wheel', nhưng không ai trong số họ đã tạo ra sự khác biệt.

Để đăng nhập vào MySQL làm người dùng gốc, bạn có thể sử dụng:

mysql -u root -p

Và sau đó nhập mật khẩu MySQL của bạn.


Để đăng nhập với tư cách là người dùng khác, bạn sẽ phải tạo người dùng đó trước và cấp cho anh ta các đặc quyền.

Tạo người dùng bằng cách sử dụng - Thay đổi

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
6 theo tên người dùng bạn muốn và
$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
7 cho mật khẩu bạn chọn.

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Đáng buồn thay, tại thời điểm này

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
6 không có quyền làm bất cứ điều gì với cơ sở dữ liệu. Do đó, giai đoạn đầu tiên là cấp cho người dùng các đặc quyền để làm 'những việc'. Để cấp tất cả các đặc quyền (chọn, tạo, xóa, cập nhật, thả, v.v.) trên tất cả các cơ sở dữ liệu và bảng, chạy:
Therefore the first stage is to grant the user the privileges to do 'things'.
To grant all privileges (select, create, delete, update, drop, etc) on all databases and tables, run:

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

Để cấp một đặc quyền cụ thể trên một cơ sở dữ liệu và bảng cụ thể, chỉ cần chạy:

GRANT [type of privilege] ON [database name].[table name] TO '[username]'@'localhost';

Nếu bạn cần từ chối hoặc thu hồi một đặc quyền nhất định, chỉ cần chạy:

REVOKE [type of permission] ON [database name].[table name] FROM '[username]'@'localhost';

Nguồn: https://www.digitalocean.com/community/articles/how-to-create-a-new-user-and-grant-permissions-in-mysql

Sử dụng GUI Mở Workbench MySQL làm quản trị viên (nhấp chuột phải, chạy làm quản trị viên). Nhấp vào Tệp> Tạo lược đồ để tạo lược đồ cơ sở dữ liệu. Nhập tên cho lược đồ và nhấp vào Áp dụng. Trong tập lệnh SQL áp dụng cho cơ sở dữ liệu, nhấp vào Áp dụng để chạy lệnh SQL tạo lược đồ.

Chúng ta có thể tạo cơ sở dữ liệu trong MySQL không?

mysql> create database new_database;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'new_database'

Đây là những đặc quyền của tôi hiện tại

Grants for root@localhost                                               
+--------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD  |
| GRANT ALL PRIVILEGES ON `testdb`.* TO 'root'@'localhost'    

Làm thế nào để tôi có được tất cả các đặc quyền hoặc siêu nhân để root@localhost

Đã hỏi ngày 15 tháng 6 năm 2016 lúc 20:57Jun 15, 2016 at 20:57

Hướng dẫn can not create database in mysql? - không thể tạo cơ sở dữ liệu trong mysql?

1

Thử đăng nhập như thế này

mysql -u root -p

Bạn đang bảo nó đăng nhập làm root người dùng bằng mật khẩu bạn sẽ cung cấp.

Nó sẽ nhắc bạn về mật khẩu của bạn và cho phép bạn truy cập MySQL.

Đó là cách tôi truy cập nó dưới dạng gốc và không có vấn đề gì với việc thực hiện các thay đổi.

Bạn có thể thử cấp tất cả các đặc quyền trên cơ sở dữ liệu sau khi tạo nó:

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
1

Sau đó, bạn có thể hiển thị các khoản tài trợ cho root và xác minh nó có quyền truy cập:

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
2

Đã trả lời ngày 15 tháng 6 năm 2016 lúc 21:22Jun 15, 2016 at 21:22

Hướng dẫn can not create database in mysql? - không thể tạo cơ sở dữ liệu trong mysql?

5

3.3.1 & nbsp; Tạo và chọn cơ sở dữ liệu

Nếu quản trị viên tạo cơ sở dữ liệu của bạn cho bạn khi thiết lập quyền của mình, bạn có thể bắt đầu sử dụng nó. Nếu không, bạn cần tự tạo nó:

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
3

Theo Unix, tên cơ sở dữ liệu nhạy cảm với trường hợp (không giống như các từ khóa SQL), do đó bạn phải luôn gọi cơ sở dữ liệu của mình là

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
9, không phải là
$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx  8 _mysql  _mysql  272 Apr 12 11:55 mysql5
0,
$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx  8 _mysql  _mysql  272 Apr 12 11:55 mysql5
1 hoặc một số biến thể khác. Điều này cũng đúng với tên bảng. . Cơ sở dữ liệu đã được tạo.)

Ghi chú

Nếu bạn gặp lỗi như lỗi 1044 (42000): Truy cập bị từ chối cho người dùng 'micah'@'localhost' vào cơ sở dữ liệu 'Menagerie' khi cố gắng tạo cơ sở dữ liệu, điều này có nghĩa là tài khoản người dùng của bạn không có đặc quyền cần thiết để thực hiện vì thế. Thảo luận về điều này với Quản trị viên hoặc xem Phần & NBSP; 6.2, Kiểm soát truy cập và quản lý tài khoản.ERROR 1044 (42000): Access denied for user 'micah'@'localhost' to database 'menagerie' when attempting to create a database, this means that your user account does not have the necessary privileges to do so. Discuss this with the administrator or see Section 6.2, “Access Control and Account Management”.

Tạo cơ sở dữ liệu không chọn nó để sử dụng; Bạn phải làm điều đó một cách rõ ràng. Để tạo

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
9 Cơ sở dữ liệu hiện tại, hãy sử dụng câu lệnh này:

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
4

Cơ sở dữ liệu của bạn chỉ cần được tạo một lần, nhưng bạn phải chọn nó để sử dụng mỗi khi bạn bắt đầu phiên MySQL. Bạn có thể làm điều này bằng cách đưa ra một tuyên bố

$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx  8 _mysql  _mysql  272 Apr 12 11:55 mysql5
3 như trong ví dụ. Ngoài ra, bạn có thể chọn cơ sở dữ liệu trên dòng lệnh khi bạn gọi MySQL. Chỉ cần chỉ định tên của nó sau bất kỳ tham số kết nối nào mà bạn có thể cần cung cấp. Ví dụ:mysql session. You can do this by issuing a
$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx  8 _mysql  _mysql  272 Apr 12 11:55 mysql5
3 statement as shown in the example. Alternatively, you can select the database on the command line when you invoke mysql. Just specify its name after any connection parameters that you might need to provide. For example:

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
5

Quan trọng

$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
9 Trong lệnh vừa hiển thị không phải là mật khẩu của bạn. Nếu bạn muốn cung cấp mật khẩu của mình trên dòng lệnh sau tùy chọn
$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx  8 _mysql  _mysql  272 Apr 12 11:55 mysql5
5, bạn phải làm như vậy mà không có không gian can thiệp (ví dụ: như -p ____ ____ 17, không phải là -p
$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
7). Tuy nhiên, việc đặt mật khẩu của bạn trên dòng lệnh không được khuyến nghị, vì làm như vậy để hiển thị nó để rình mò bởi những người dùng khác đăng nhập vào máy của bạn.not your password. If you want to supply your password on the command line after the
$ ls -l /opt/local/var/db/
total 0
drwxrwxrwx  8 _mysql  _mysql  272 Apr 12 11:55 mysql5
5 option, you must do so with no intervening space (for example, as -p
$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
7
, not as -p
$ mysql5 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.61 Source distribution

mysql> create database dbname;
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'dbname'
7
). However, putting your password on the command line is not recommended, because doing so exposes it to snooping by other users logged in on your machine.

Ghi chú

Nếu bạn gặp lỗi như lỗi 1044 (42000): Truy cập bị từ chối cho người dùng 'micah'@'localhost' vào cơ sở dữ liệu 'Menagerie' khi cố gắng tạo cơ sở dữ liệu, điều này có nghĩa là tài khoản người dùng của bạn không có đặc quyền cần thiết để thực hiện vì thế. Thảo luận về điều này với Quản trị viên hoặc xem Phần & NBSP; 6.2, Kiểm soát truy cập và quản lý tài khoản.


Tại sao cơ sở dữ liệu không tạo trong MySQL?

Một lỗi xảy ra nếu cơ sở dữ liệu tồn tại và bạn không chỉ định nếu không tồn tại. Tạo cơ sở dữ liệu không được phép trong một phiên có câu lệnh bảng khóa hoạt động.if the database exists and you did not specify IF NOT EXISTS . CREATE DATABASE is not permitted within a session that has an active LOCK TABLES statement.

Làm cách nào để tạo cơ sở dữ liệu theo cách thủ công trong MySQL?

Sử dụng GUI Mở Workbench MySQL làm quản trị viên (nhấp chuột phải, chạy làm quản trị viên).Nhấp vào Tệp> Tạo lược đồ để tạo lược đồ cơ sở dữ liệu.Nhập tên cho lược đồ và nhấp vào Áp dụng.Trong tập lệnh SQL áp dụng cho cơ sở dữ liệu, nhấp vào Áp dụng để chạy lệnh SQL tạo lược đồ.Open the MySQL Workbench as an administrator (Right-click, Run as Admin). Click on File>Create Schema to create the database schema. Enter a name for the schema and click Apply. In the Apply SQL Script to Database window, click Apply to run the SQL command that creates the schema.

Chúng ta có thể tạo cơ sở dữ liệu trong MySQL không?

Chúng ta có thể tạo một cơ sở dữ liệu mới trong MySQL bằng cách sử dụng câu lệnh CREATE DATABASE với cú pháp dưới đây: Tạo cơ sở dữ liệu [nếu không tồn tại] Database_name.[Bộ ký tự Charset_name] [Collate Collation_Name]; with the below syntax: CREATE DATABASE [IF NOT EXISTS] database_name. [CHARACTER SET charset_name] [COLLATE collation_name];

Làm cách nào để cho phép người dùng tạo cơ sở dữ liệu trong MySQL?

mysql> cấp tạo trên *. * to 'LinuxConfig'@'localhost';Thay vào đó, nếu bạn muốn cấp quyền của người dùng để chỉ tạo các bảng mới trong một cơ sở dữ liệu nhất định, giả sử cơ sở dữ liệu TestDB, chúng tôi sẽ sử dụng lệnh sau: mysql> Crean created trên TestDB. * TO 'linuxconfig'@'localhost'; If you would instead prefer to grant your user permissions to only create new tables within a certain database, say the testdb database, we would use the following command: mysql> GRANT CREATE ON testdb.