Pages

Friday, September 7, 2012

Basics of MYSQL

MySQL is the world's most used open source relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases.

It is named after co-founder Michael Widenius' daughter, My. The SQL phrase stands for Structured Query Language.

ts source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL was owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation.

MySQL is a popular choice of database for use in web applications, and is a central component of the widely used LAMP open source web application software stack—LAMP is an acronym for "Linux, Apache, MySQL, Perl/PHP/Python". Free-software-open source projects that require a full-featured database management system often use MySQL.

Start the console: mysql

List all databases: show databases;

Switch to a database: use $dbname;

List tables in a current database: show tables;

List columns in a given table: describe $tablename;

Setting permissions to a database: GRANT SELECT ON $database.* TO '$user_name'@'%' IDENTIFIED BY '$password';

Deleting rows: delete from $db.$table where $condition;

Selects: select count(*) from $db.$table;

Altering a table:

ALTER TABLE get_cookie_log ADD COLUMN log_id INT(10) NOT NULL auto_increment, ADD PRIMARY KEY(log_id);`
ALTER TABLE get_cookie_log ADD COLUMN log_id INT(10) NOT NULL auto_increment, ADD INDEX(log_id);`
ALTER TABLE verify_reg_code_log ADD COLUMN log_id INT(10) NOT NULL auto_increment, ADD INDEX(log_id);


Backup database: mysqldump $database [[-all] | [$table]]s >$file-name.sql

Import database:
mysql -e "DROP DATABASE $db; CREATE DATABASE $db;"
mysql $databasename <$file-name.sql

No comments:

Post a Comment