Musings

A random collection

TECH: Basic MySQL Commands

  1. An example MySQL session:
    CREATE DATABASE somedb;
    CREATE USER "someuser"@"localhost" IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON somedb.* TO "someuser"@"localhost";
    FLUSH PRIVILEGES;
    
    SHOW DATABASES;
    USE somedb;
    SHOW TABLES;
    
    DROP TABLE tablename;
    
  2. Create a table:
    CREATE TABLE tablename
    (
        colname1 DATATYPE,
        colname2 DATATYPE,
        PRIMARY KEY (colname1)
    );
    INSERT INTO tablename VALUES
    ( value1, value2 )
    ;
    
  3. Alter a table
    ALTER TABLE tablename
        ADD COLUMN colname datatype,
        ADD PRIMARY KEY (colname2)
    ;
    [/sourcecode language="sql"]</li>
    
    <li>Select rows
    
    SELECT * FROM tablename;
    
  4. Update rows
    UPDATE tablename SET
        colname = value;
    
  5. Delete rows
    DELETE FROM tablename WHERE condition;
    

First time startup

Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h fc13 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

Written by curious

January 26, 2010 at 11:33 am

Posted in databases