Upload
mohd-yasin-karim
View
1.066
Download
1
Tags:
Embed Size (px)
DESCRIPTION
mysql administration with command
Citation preview
MySQLAdministration
Mohd Yasin Abd [email protected]
Configuring Monitoring, Starting & Stopping Managing Users and Connection Performing backups Others
Introduction to MySQL Administrator
Terminology
Mysqladmin or mysql GUI
◦ MySQL Administrator◦ MySQL Workbench◦ phpMyAdmin
Tools
OS packages place files in many areas and varies◦ e.g. /usr/lib, /var/lib, /var/log, /etc
Source rpm, yum, .tar.gz, exe Online/repo update
◦ #yum update mysql-* For Ms Windows Environment
Local folder normally Program Files folder
MySQL Installation
C:\>cd \local\mysql\binC:\local\mysql\bin>
Start MySQL process before create database To configure MySQL start at boot time
Or using GUI tools such as OS Services Management
Starting MySQL
#chkconfig mysqld on
After boot time using the services commands
Remember to restart mysqld process every time after configuration changed
Starting & Stopping the MySQL Server
#service mysqld start#service mysqld stop#Service mysqld restart
to know whether your MySQL server is alive
Should get response process ID numbers Or
The "mysqld is alive" message tells you that your MySQL server is running ok. If your MySQL server is not running, you will get a "connect ... failed" message.
Check process
#pgrep mysqld
#mysqladmin –u root –p ping
my.cnf◦ Watch out for /etc/my.cnf, /etc/mysql/my.cnf
To get the server listening on all interfaces, use 0.0.0.0 as the bind address. i.e.:--bind-address=0.0.0.0
MySQL Configuration
Configured to listen TCP/IP Port (default 3306)
Additional Instances◦ Different Ports◦ Different IP’s using default Port
Local connection using Socket
MySQL Ports & Socket
Login to MySQL server
Create a database
List all databases on the MySQL server
MySQL Client
#mysql –h hostname –u root -p
msql> create database [databasename];
msql> show databases;
Swicth to a database
To see all the tables in the db
To delete a db
MySQL Client
msql> use [db_name];
msql> show tables;
msql> drop database [databasename];
To see database’s field formats
To delete a table
Show all data in a table
MySQL Client
msql> drop table [table name];
msql> SELECT * FROM [table name];
msql> describe [table name];
SHOW TABLES; SHOW WARNINGS; SHOW STATUS; FLUSH STATUS; SHOW VARIABLES; SHOW VARIABLES LIKE ‘%size%’; SHOW VARIABLES LIKE ‘sort_buffer_size’; SHOW GLOBAL STATUS;
SHOW Commands
to check version number of your MySQL server
MySQL Check Version
C:\local\mysql\bin>mysqladmin -u root version
According to the /etc/my.cnf Usually located in subdirectory
/var/lib/mysql/ directory Example : test database
◦ /var/lib/mysql/test
Location of MySQL Databases
Root or superuser account is used to create and delete database
New installation MySQL set password
Creating a MySQL ‘root’ Account
#mysqladmin –u root password new-password
to know what else you can do with "mysqladmin", you should run the "-?"
Mysqladmin tool
#mysqladmin –?
Creating new user
Administering Users
# mysql -u root -pmysql> use mysql;mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password'));mysql> flush privileges;
Change a user password from unix shell
Change user password from MySQL prompt
# mysqladmin -u username -h hostname.org -p password 'new-password'
# mysql -u root -pmysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');mysql> flush privileges;
Update root password
Allow the user “bob” to connect to server from localhost using password ‘passwd’
# mysqladmin -u root -p oldpassword newpassword
# mysql -u root -pmysql> use mysql;mysql> grant usage on *.* to bob@localhost identified by 'passwd';mysql> flush privileges;
Give user privileges for a db.
# mysql -u root -pmysql> use mysql;mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');mysql> flush privileges;
or
mysql> grant all privileges on databasename.* to username@localhost;mysql> flush privileges;
To update info already in table
Delete a rows from table
Update database permissions/privileges
mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';
mysql> DELETE from [table name] where [field name] = 'whatever';
mysql> flush privileges;
Dump all databases for backup
Dump one database for backup
Dump a table from a database
Backup
# mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql
# mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql
# mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
Restore database / table from backup
Restore
# mysql -u username -ppassword databasename < /tmp/databasename.sql
Example
Create Table
mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default ‘yasin');
mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));
Thanks