Some tips of using MySQL on Linux
Login to MySQL using mysql client in console/terminal:
mysql -u username -p dbname
or
mysql -u username -ppassword dbname
or (using current username to log in)
mysql -ppassword dbname
security tip: username root is the default administrator. Do not use it in a live environment. Create a new one and set the appropriate permission for it.
Create a new database:
mysqladmin -u username -ppassword create databasename
(username is the administrator username that able to create a new database ie root)
or you can log in to mysql using mysql client in console. Example:
//create table with myisam engine.
CREATE TABLE mytable (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id),
value_a TINYINT
) TYPE=MYISAM
//create table with HEAP engine.
CREATE TABLE mytable (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id),
value_a TINYINT
) TYPE=HEAP
Delete a database:
Login to mysql and issue command drop database databasename.
(Make sure you use usernames with correct priviledge to drop a database)
What is the size of my database?
database size = the sum of all table sizes + all index sizes
- Open a text editor (eg. Notepad)
- Copy and paste the code below into your text editor ( replace username, password and dbid accordingly):
mysql database sizeif ($filesize < filesize ="">
# in at least kilobytes.
for ($i = 0; $filesize > 1024; $i++) $filesize /= 1024;
$file_size_info['size'] = ceil($filesize);
$file_size_info['type'] = $bytes[$i];
return $file_size_info; } $db_server = 'mysqlhost'; $db_user = 'username'; $db_pwd = 'password'; $db_name = 'dbid';
$db_link = @mysql_connect($db_server, $db_user, $db_pwd)
or exit('Could not connect: ' . mysql_error()); $db = @mysql_select_db($db_name, $db_link) or exit('Could not select database: ' . mysql_error());
// Calculate DB size by adding table size + index size:
$rows = mysql_query("SHOW table STATUS"); $dbsize = 0;
while ($row = mysql_fetch_array($rows)) {$dbsize += $row['Data_length'] + $row['Index_length']; } print "database size is: $dbsize bytes "; print 'or';
$dbsize = file_size_info($dbsize); print "database size is: {$dbsize['size']} {$dbsize['type']}"; ?>
put this php script into your accessible directory. (taken from here).
Nice reading : Overcoming MySQL's 4GB limit by Jeremy Zawodny.
To know what engine your database is using:
SHOW TABLE STATUS FROM yourdbname
ALTER TABLE isamtable CHANGE TYPE=InnoDB
or you can use utility mysql_convert_table_format :
mysql_convert_table_format --user=username --pasword=password --type=innodb databasename tables
0 comments:
Post a Comment