Download Creating Mysql databse Users and changing Password

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

DBase wikipedia , lookup

Microsoft Access wikipedia , lookup

IMDb wikipedia , lookup

Oracle Database wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

SQL wikipedia , lookup

Concurrency control wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Functional Database Model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Database wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

PL/SQL wikipedia , lookup

Ingres (database) wikipedia , lookup

Clusterpoint wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

ContactPoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
What is MySQL
MySQL is a open source Relational Database Management System. MySQL is very fast
reliable and flexible Database Management System. It provides a very high performance
and it is multi threaded and multi user Relational Database management system.
MySQL is one of the most popular relational database Management System on the web.
The MySQL Database has become the world's most popular open source Database,
because it is free and available on almost all the platforms. The MySQL can run on Unix
, window, and Mac OS. MySQL is used for the internet applications as it provides good
speed and is very secure. MySQL was developed to manage large volumes of data at very
high speed to overcome the problems of existing solutions. MySQL can be used for
verity of applications but it is mostly used for the web applications on the internet.
MySQL Features
1. MySQL are very fast and much reliable for any type of application.
2. MySQL is very Lightweight application.
3. MySQL command line tool is very powerful and can be used to run SQL queries
against database.
4. MySQL Supports indexing and binary objects.
5. It is allow changes to structure of table while server is running.
6. MySQL has a wide user base.
7. It is a very fast thread-based memory allocation system.
8. MySQL Written in C and C++ language.
9. MySQL code is tested with different compilers.
10. MySQL is available as a separate program for use in a client/server network
environment.
11. The MySQL available for the most Unix operating platform.
12. MySQL are the available for window operating system window NT, window 95
,and window 98.
13. MySQL available for OS/2.
14. Programming libraries for C, Python, PHP, Java , Delphi etc. are available to
connect to MySQL database.
MySQL Advantages:
Reliability and Performance
MySQL is very reliable and high performance relational database management system. It
can used to store many GB's of data into database.
Availability of Source
MySQL source code is available that's why now you can recompile the source code.
Cross-Platform support
MySQL supports more then twenty different platform including the major Linux
distribution .Mac OS X ,Unix and Microsoft windows.
Large pool of Trained and Certified Developers
MySQL is very popular and it is world most popular open source Database. So it is easy
to find high quality staff around the world.
Powerful Uncomplicated software
The MySQL has most capabilities to handle most corporate database application and used
to very easy and fast
MySQL 5 Features
There are three feature of MySQL 5.0 version:
Views
Views is a virtual table which acts as a table but it contains no data. Views are
created using columns from one or more tables.

Stored Procedures and Functions
MySQL 5.0 now support Stored Procedures and Functions. This allows you to
embed business logic at database level.

Triggers
The Triggers is another very imported feature available with MySQL 5.0. Now
can add some business logic whenever data is inserted, Deleted or updated in the
table.
Cursors

select version();
Numeric Data Types:
MySQL uses all the standard ANSI SQL numeric data types, so if you're coming to
MySQL from a different database system, these definitions will look familiar to you. The
following list shows the common numeric data types and their descriptions.



INT - A normal-sized integer that can be signed or unsigned. If signed, the
allowable range is from -2147483648 to 2147483647. If unsigned, the allowable
range is from 0 to 4294967295. You can specify a width of up to 11 digits.
TINYINT - A very small integer that can be signed or unsigned. If signed, the
allowable range is from -128 to 127. If unsigned, the allowable range is from 0 to
255. You can specify a width of up to 4 digits.
SMALLINT - A small integer that can be signed or unsigned. If signed, the
allowable range is from -32768 to 32767. If unsigned, the allowable range is from
0 to 65535. You can specify a width of up to 5 digits.





MEDIUMINT - A medium-sized integer that can be signed or unsigned. If
signed, the allowable range is from -8388608 to 8388607. If unsigned, the
allowable range is from 0 to 16777215. You can specify a width of up to 9 digits.
BIGINT - A large integer that can be signed or unsigned. If signed, the allowable
range is from -9223372036854775808 to 9223372036854775807. If unsigned, the
allowable range is from 0 to 18446744073709551615. You can specify a width of
up to 11 digits.
FLOAT(M,D) - A floating-point number that cannot be unsigned. You can define
the display length (M) and the number of decimals (D). This is not required and
will default to 10,2, where 2 is the number of decimals and 10 is the total number
of digits (including decimals). Decimal precision can go to 24 places for a
FLOAT.
DOUBLE(M,D) - A double precision floating-point number that cannot be
unsigned. You can define the display length (M) and the number of decimals (D).
This is not required and will default to 16,4, where 4 is the number of decimals.
Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym for
DOUBLE.
DECIMAL(M,D) - An unpacked floating-point number that cannot be unsigned.
In unpacked decimals, each decimal corresponds to one byte. Defining the display
length (M) and the number of decimals (D) is required. NUMERIC is a synonym
for DECIMAL.
Date and Time Types:
The MySQL date and time datatypes are:





DATE - A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31.
For example, December 30th, 1973 would be stored as 1973-12-30.
DATETIME - A date and time combination in YYYY-MM-DD HH:MM:SS
format, between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. For example,
3:30 in the afternoon on December 30th, 1973 would be stored as 1973-12-30
15:30:00.
TIMESTAMP - A timestamp between midnight, January 1, 1970 and sometime
in 2037. This looks like the previous DATETIME format, only without the
hyphens between numbers; 3:30 in the afternoon on December 30th, 1973 would
be stored as 19731230153000 ( YYYYMMDDHHMMSS ).
TIME - Stores the time in HH:MM:SS format.
YEAR(M) - Stores a year in 2-digit or 4-digit format. If the length is specified as
2 (for example YEAR(2)), YEAR can be 1970 to 2069 (70 to 69). If the length is
specified as 4, YEAR can be 1901 to 2155. The default length is 4.
String Types:
Although numeric and date types are fun, most data you'll store will be in string format.
This list describes the common string datatypes in MySQL.







CHAR(M) - A fixed-length string between 1 and 255 characters in length (for
example CHAR(5)), right-padded with spaces to the specified length when stored.
Defining a length is not required, but the default is 1.
VARCHAR(M) - A variable-length string between 1 and 255 characters in
length; for example VARCHAR(25). You must define a length when creating a
VARCHAR field.
BLOB or TEXT - A field with a maximum length of 65535 characters. BLOBs
are "Binary Large Objects" and are used to store large amounts of binary data,
such as images or other types of files. Fields defined as TEXT also hold large
amounts of data; the difference between the two is that sorts and comparisons on
stored data are case sensitive on BLOBs and are not case sensitive in TEXT
fields. You do not specify a length with BLOB or TEXT.
TINYBLOB or TINYTEXT - A BLOB or TEXT column with a maximum
length of 255 characters. You do not specify a length with TINYBLOB or
TINYTEXT.
MEDIUMBLOB or MEDIUMTEXT - A BLOB or TEXT column with a
maximum length of 16777215 characters. You do not specify a length with
MEDIUMBLOB or MEDIUMTEXT.
LONGBLOB or LONGTEXT - A BLOB or TEXT column with a maximum
length of 4294967295 characters. You do not specify a length with LONGBLOB
or LONGTEXT.
ENUM - An enumeration, which is a fancy term for list. When defining an
ENUM, you are creating a list of items from which the value must be selected (or
it can be NULL). For example, if you wanted your field to contain "A" or "B" or
"C", you would define your ENUM as ENUM ('A', 'B', 'C') and only those values
(or NULL) could ever populate that field.
Create, List, Use and Delete Databases Commands
create database
This command is used to create a Database on the sql server..
Syntax: create database [db name];
Eg:
create database employees;
show databases
This command id used to list all databases on the sql server.
Syntax: show databases;
use database
This command is used to switch to a database.
Syntax: use [db name];
drop database dbname
This command is used to delete a database.
Syntax: drop database [db name];
Creating tables and working with it
create tabe
This command is used to create tables in a database.
Eg:
CREATE TABLE example(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
age INT);
show tables
This command is see all the tables in the database.
describe table
To see database's field formats.
describe [table name];
drop table tablename
To delete a table.
drop table [table name];
RENAME TABLE user TO dummy_user
Show all data in a table.
SELECT * FROM [table name];
Returns the columns and column information pertaining to the designated table.
show columns from [table name];
Show certain selected rows with the value "something".
SELECT * FROM [table name] WHERE [field name] = "something";
Show all records containing the name "Telson" AND the phone number '2255'.
SELECT * FROM [table name] WHERE name = "Telson" AND phone_number = '2255';
Show all records not containing the name "Telson" AND the phone number '2255' order
by the phone_number field.
SELECT * FROM [table name] WHERE name != "Telson" AND phone_number =
'2255' order by phone_number;
Show all records starting with the letters 'Tel' AND the phone number '2255'.
SELECT * FROM [table name] WHERE name like "Tel%" AND phone_number =
'2255';
Use a regular expression to find records. Use "REGEXP BINARY" to force casesensitivity. This finds any record beginning with a.
SELECT * FROM [table name] WHERE rec RLIKE "^a$";
Show unique records.
SELECT DISTINCT [column name] FROM [table name];
Show selected records sorted in an ascending (asc) or descending (desc).
SELECT [column1],[column2] FROM [table name] ORDER BY [column2] DESC;
Return number of rows.
SELECT COUNT(*) FROM [table name];
Sum column.
SELECT SUM(*) FROM [table name];
Join tables on common columns.
select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person
on lookup.personid=person.personid=statement to join birthday in person table with
primary illustration id;
Creating Mysql databse Users and changing Password
Switch to the mysql db. Create a new user.
INSERT INTO [table name] (Host,User,Password)
VALUES('%','user',PASSWORD('password'));
Change a users password.(from unix shell).
[mysql dir] mysqladmin -u root -h hostname.blah.org -p password 'new-password'
Change a users password.(from MySQL prompt).
SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');
Allow the user "telson" to connect to the server from localhost using the password
"passwd"
grant usage on *.* to telson@localhost identified by 'passwd';
Switch to mysql db.Give user privilages for a db.
INSERT INTO [table name]
(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv)
VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
or
grant all privileges on databasename.* to username@localhost;
Modifying and Updating tables in MySQL
To update info already in a table.
UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where
[field name] = 'user';
Delete a row(s) from a table.
DELETE from [table name] where [field name] = 'something';
Update database permissions/privilages.
FLUSH PRIVILEGES;
Delete a column.
alter table [table name] drop column [column name];
Add a new column to db.
alter table [table name] add column [new column name] varchar (20);
Change column name.
alter table [table name] change [old column name] [new column name] varchar (50);
Make a column bigger.
alter table [table name] modify [column name] VARCHAR(4);
Creating MySQL Database backup’s and Restoring Databases
Dump all databases for backup. Backup file is sql commands to recreate all db's.
[mysql dir] mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql
Dump one database for backup.
[mysql dir] mysqldump -u username -ppassword --databases databasename
>/tmp/databasename.sql
Dump a table from a database.
[mysql dir] mysqldump -c -u username -ppassword databasename tablename >
/tmp/databasename.tablename.sql
Restore database (or database table) from backup.
[mysql dir] mysql -u username -ppassword databasename < /tmp/databasename.sql