How do i create in a table in phpmyadmin?

2019-03-04 00:46发布

Whenever I go to sql in phpmyadmin to create a table, I put this code in:

CREATE TABLE IF NOT EXISTS `users` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(255) NOT NULL,
      `first_name` varchar(255) NOT NULL,
      `last_name` varchar(255) NOT NULL,
      `email` varchar(255) NOT NULL,
      `password` varchar(255) NOT NULL,
      `sign_up_date` date NOT NULL,
      `activated` enum('0','1') NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

it says:#1046 - No database selected but when I put:

CREATE DATABASE data;
USE data;
CREATE TABLE IF NOT EXISTS `users` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(255) NOT NULL,
      `first_name` varchar(255) NOT NULL,
      `last_name` varchar(255) NOT NULL,
      `email` varchar(255) NOT NULL,
      `password` varchar(255) NOT NULL,
      `sign_up_date` date NOT NULL,
      `activated` enum('0','1') NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

it says that it could not create the database?

3条回答
叼着烟拽天下
2楼-- · 2019-03-04 01:02

Since you have got your sql statement, then just go to phpMyAdmin > login (if there is need for it) > select database you want to use, find it in Right Hand Side , example 'test'. tehn simply just find the tab named sql and click it, after that just paste your statements

查看更多
祖国的老花朵
3楼-- · 2019-03-04 01:06

One server can contain multiple databases. If you login into PHPMyAdmin, you choose a server to login to. After you've logged in, you have to select your database to be able to make changes to it.

So you don't need to create a database. You just need to select it. You can do that with the USE <databasename> statement, or though the PHPMyAdmin interface. In your second snippet, you already used have the USE statement. You just need to remove the CREATE DATABASE statement.

Same goes for creating the table, by the way. PHPMyAdmin provides an interface to add a table field by field without having to write the SQL for it. Although it can't hurt to know the syntax, of course.

查看更多
孤傲高冷的网名
4楼-- · 2019-03-04 01:07

Step 1: Choose an existing Database or create a new Database.

Step 1:

Step 2: Choose the SQL tab and add your code to create a table. Step 2:

查看更多
登录 后发表回答