MYSQL MySQL is a database.The data in MySQL is stored in database objects called tables.A table is a collections of related data entries and it consists of columns and rows.Databases are useful when storing information categorically. A company may have a database with the following tables: "Employees", "Products", "Customers" and "Orders".
It's simple to install MySQL on Linux using the RPM file.
1. Become the superuser if you are working in your account. (Type "su" and the prompt and give the root password).
2. Change to the directory that has the RPM download.
3. Type the following command at the prompt:
rpm -ivh "mysql_file_name.rpm"
Similarly you can also install the MySQL client and MySQL development RPMs if you've downloaded them.
Alternatively, you can install the RPMs through GnoRPM (found under System).
4.Now we'll set a password for the root user. Issue the following at the prompt:
mysqladmin -u root password mysqldata
5.It is now time to test the programs. Typing the following at the prompt starts the mysql client program. The system asks for the the password.Type the root password (mysqldata).If you don't get the prompt for password, it might be because MySQL Server is not running. To start the server, change to /etc/rc.d/init.d/ directory and issue the command ./mysql start (or mysql start depending on the value of the PATH variable on your system). Now invoke mysql client program. 6.Once MySQL client is running, you should get the mysql> prompt. Type the following at this prompt: show databases;
7. You should now get a display similar to: We've successfully installed MySQL on your system
I The MySQL server configuration normally started during installation process . The MySQL configuration wizard can be launched by clicking the MySQL server instance configuration wizard entry in the MySQL section of the window start menu. Another way to launch the configuration wizard, you can launch the MySQLInstanceConfig.exe file directly from bin directory of your MySQL installation. The MySQL server configuration wizard sets configuration variables values in my.ini file in the installation directory for the MySQL server. --defaults-file="C:Program FilesMySQLMySQL Server 5.0my.ini" Path "C:Program FilesMySQLMySQL Server 5.0" is installation directory of MySQL server . The --defaults-file option instructs the MySQL server to read the specified file for configuration options when it starts. The MySQL client and utilities like mysql and mysqldump command-line client are unable to locate the my.ini file locate in the server installation directory. The MySQL use window server 2003, window server 2000 and window XP, MySQL server configuration wizard will configure with MySQL quickly without having to make many decisions about server configuration. CONFIGURATION
The MySQL server
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
Where do all the plugins live
plugin_dir = /opt/lampp/lib/mysql/plugin/
Don't listen on a TCP/IP port at all. This can be a security enhancement,
if all processes that need to connect to mysqld run on the same host.
All interaction with mysqld must be made via Unix sockets or named pipes.
Note that using this option without enabling named pipes on Windows
(via the "enable-named-pipe" option) will render mysqld useless!
Two methods to configure the host as a replication slave
1) Use the CHANGE MASTER TO command (fully described in our manual) -
The syntax is:
CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
where you replace <host>, <user>, <password> by quoted strings and
<port> by the master's port number (3306 by default).
CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
Set the variables below. However, in case you choose this method, then start replication for the first time (even unsuccessfully, for example if you mistyped the password in master-password and the slave fails to connect), the slave will create a master.info file, and any later change in this file to the variables' values below will be ignored and overridden by the content of the master.info file, unless you shutdown the slave server, delete master.info and restart the slaver server.
A query is a question or a request.
With MySQL, we can query a database for specific information and have a recordset returned.
SELECT LastName FROM Persons
The Create command is used to create a table by specifying the tablename, fieldnames and constraints as shown below.
Explanation: It is used to create a shorthand reference to elements with long names to make the SQL statements shorter and reduce the chance of typos in the longer names.
SQL joins are used to query data from two or more tables, based on a relationship between certain columns in these tables.The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.Tables in a database are often related to each other with keys.A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.
DIFFERENT SQL JOINS
JOIN: Return rows when there is at least one match in both tables
LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table
RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
FULL JOIN: Return rows when there is a match in one of the tables
The INNER JOIN keyword return rows when there is at least one match in both tables.
SQL INNER JOIN Syntax
SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name;
LASTNAME FIRST NAME ORDER NO. Hansen Ola 22456 Hansen Ola 24562 Pettersen Kari 77895 Pettersen Kari 44678
The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table (table_name2).
SQL LEFT JOIN Syntax:
SELECT column_name(s) FROM table_name1
LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name
The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no matches in the left table (table_name1).
SQL RIGHT JOIN Syntax:
SELECT column_name(s) FROM table_name1
RIGHT JOIN table_name2 ON table_name1.column_name=table_name2.column_name
The FULL JOIN keyword return rows when there is a match in one of the tables.
SQL FULL JOIN Syntax:
SELECT column_name(s) FROM table_name1
FULL JOIN table_name2 ON table_name1.column_name=table_name2.column_name
Constraints are used to limit the type of data that can go into a table.Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement).
We have the following constraints:
* NOT NULL
* PRIMARY KEY
* FOREIGN KEY
SQL aggregate functions return a single value, calculated from values in a column.
AVG() - Returns the average value
COUNT() - Returns the number of rows
FIRST() - Returns the first value
LAST() - Returns the last value
MAX() - Returns the largest value
MIN() - Returns the smallest value
SUM() - Returns the sum
SQL scalar functions return a single value, based on the input value.
* UCASE() - Converts a field to upper case
* LCASE() - Converts a field to lower case
* MID() - Extract characters from a text field
* LEN() - Returns the length of a text field
* ROUND() - Rounds a numeric field to the number of decimals specified
* NOW() - Returns the current system date and time
* FORMAT() - Formats how a field is to be displayed