Below rpms are required to run mksql on CentOS.
- mysql-version.rpm (Required)
- mysql-server-version.rpm (Required)
- mysqlclient9-version.rpm (Shared object libraries)
- mysql-devel-version.rpm (C include files and libraries for developers)
- php-mysql-version.rpm (For accessing MySQL database from php)
root@centosserver
# mysql -h localhost -u root -p<passwd>
Welcome
to the MySQL monitor. Commands end with
; or \g.
Your
MySQL connection id is 7
Server
version: 5.1.73 Source distribution
Copyright
(c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle
is a registered trademark of Oracle Corporation and/or its
affiliates.
Other names may be trademarks of their respective
owners.
Type
'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
show databases;
Shutdown my SQL DB
[prompt]$ /etc/rc.d/init.d/mysqld stop
OR
[prompt]$ service mysqld stop
[prompt]$ service mysqld stop
mysql>
CREATE USER user_name@'localhost' IDENTIFIED BY 'password';
or
generate a user by adding them to the user table directly:[prompt]$ mysql -h localhost -u root -p
mysql> use mysql;
mysql> INSERT INTO user
(Host,User,Password) VALUES('localhost','user_name',PASSWORD('PASSWD'));
####################################################################
Connect to the database
mysql -h localhost
-u root -p<passwd>
mysql> create
database vihan;
Query OK, 1 row affected (0.01
sec)
mysql> show
databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| try |
| mysql |
| test |
| vihan |
+--------------------+
5 rows in set (0.01 sec)
mysql> drop
database test;
Query OK, 0 rows affected (0.02 sec)
mysql> use
vihan;
Database changed
mysql>
mysql> show
tables;
Empty set (0.00 sec)
mysql> CREATE
TABLE pot(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
-> name VARCHAR(20),
-> food VARCHAR(30),
-> confirmed CHAR(1),
-> signup_date DATE);
Query OK, 0 rows affected (0.01 sec)
mysql> DESCRIBE
pot;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO
| PRI | NULL | auto_increment |
| name | varchar(20) |
YES |
| NULL | |
| food | varchar(30) |
YES |
| NULL | |
| confirmed | char(1) | YES
| | NULL | |
| signup_date | date |
YES |
| NULL | |
+-------------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> INSERT
INTO `pot` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL,
"John", "Casserole","Y", '2012-04-11');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT
INTO `pot` (`id`,`name`,`food`,`confirmed`,`signup_date`) VALUES (NULL,
"Tina", "Salad","Y", '2012-04-10');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT *
FROM pot;
+----+-------+----------------+-----------+-------------+
| id | name | food | confirmed | signup_date |
+----+-------+----------------+-----------+-------------+
| 1 | John | Casserole | Y | 2012-04-11 |
| 2 | Sandy | Key Lime Tarts |
N | 2012-04-14 |
| 3 | Tom | BBQ | Y | 2012-04-18 |
| 4 | Tina | Salad | Y | 2012-04-10 |
+----+-------+----------------+-----------+-------------+
4 rows in set (0.00 sec)
mysql> UPDATE
`pot`
-> SET
-> `confirmed` = 'Y'
-> WHERE `pot`.`name` ='Sandy';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> ALTER
TABLE pot ADD email VARCHAR(40);
DELETE from [table name] where [column
name]=[field text];
mysql> DELETE
from pot where name='Sandy';
No comments:
Post a Comment