2

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.

pheidlauf
  • 131
  • 1
  • 5

2 Answers2

3

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.

jynus
  • 15,057
  • 2
  • 37
  • 46
2

When you connect to MySQL from the command line, simply run:

CREATE DATABASE mydb;

What does this do ?

  • This will create the folder /var/lib/mysql/mydb
  • The ownership will be mysql:mysql
  • File permissions will be set by the mysqld process

Of course, you need to connect to MySQL as root@localhost

Notwithstanding, I would strongly advise you to MySQL Workbench because you are a beginner.

First, download and install MySQL Workbench. Then, simply download MySQL Documentation and read it through. MySQL Workbench will provide a comfortable GUI for all the basica operational aspects of creating databases, tables, and all other moving parts of MySQL.

A more seasoned DBA may construct a database with his/her bare hands. MySQL Workbench and other DBA GUIs are there to streamline that process.

RolandoMySQLDBA
  • 185,223
  • 33
  • 326
  • 536