Mysql – Creating a database with only MySQL command line

database-designdevelopmentMySQLmysql-workbench

The linux server on which I'm attempting to create a MySQL database has many difficult to work with permissions. My supervisor has tried to install MySQL Workbench on the server, but has been unable to "build" the correct install (he knows much more than me about linux command line and the server we're using than I do, and we are running on a relatively short schedule). Thus, the only tool I have with which to create a MySQL relational database is the built-in MySQL Command Line.

  • Is it possible (practically speaking) to create a functioning
    relational database using only SQL code in the command line, or will
    I eventually need a tool such as MySQL Workbench?

    • If it is possible, could you please direct me to a good
      resource/reference on how to do so?

I have minimal experience with MySQL, but am familiar with databases and am generally computer-savvy. Thanks.

Best Answer

Yes, most linux system administrators only use the command lines client (or other cli tools to work with the database). Maybe the only other thing you will need for design is a text editor (for writing easily before executing), like vi(m), nano or emacs, and pen and paper.

Here it is a first crash course:

  • Create a database:

    CREATE DATABASE your_database_name;
    
  • Change the current database:

    use your_database_name
    
  • Create your first table:

     CREATE TABLE your_table (
         id bigint unsigned PRIMARY KEY auto_increment,
         name varchar(50) NOT NULL,
         description text,
         modified_on timestamp
     ) ENGINE = InnoDB;
    
  • Populate your table:

     INSERT INTO your_table (name, description) VALUES ('pheidlauf', 'You are awesome');
    
  • Select your table:

     SELECT * FROM your_table;
    

Learn about MySQL SQL variant, in particular DDL commands, DCL and about using the command line client. There are many resources (I have just linked to wikibooks and the official MySQL documentation), but the command line client also has integrated help:

mysql> help create table

Another quick startup guide.