Tuesday, January 6, 2015

Playing around with MariaDB

[root@localhost opt]# mkdir OS_Image
[root@localhost opt]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   18G  3.4G   15G  20% /
devtmpfs                 487M     0  487M   0% /dev
tmpfs                    496M   92K  496M   1% /dev/shm
tmpfs                    496M  7.1M  489M   2% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/sda1                497M  134M  363M  27% /boot
/dev/sr0                 3.9G  3.9G     0 100% /run/media/devi/CentOS 7 x86_64
[root@localhost opt]# pwd
/opt
[root@localhost opt]# cd OS_Image/
[root@localhost OS_Image]# cd /run/media/devi/CentOS\ 7\ x86_64/
[root@localhost CentOS 7 x86_64]# ls
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL
[root@localhost CentOS 7 x86_64]# cp -rp * /opt/OS_Image/
[root@localhost CentOS 7 x86_64]# pwd
/run/media/devi/CentOS 7 x86_64
[root@localhost CentOS 7 x86_64]# vi /etc/yum.repos.d/file.repo^C
[root@localhost CentOS 7 x86_64]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# vi file.repo
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
RHEL7                                                               | 3.6 kB  00:00:00    
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
RHEL7/primary_db                                                    | 2.7 MB  00:00:00    
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
repo id                                  repo name                                   status
RHEL7                                    Centos 7 repo                               3,538
base/7/x86_64                            CentOS-7 - Base                                 0
extras/7/x86_64                          CentOS-7 - Extras                               0
updates/7/x86_64                         CentOS-7 - Updates                              0
repolist: 3,538
[root@localhost yum.repos.d]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:3d:f8:fa  txqueuelen 1000  (Ethernet)
        RX packets 199  bytes 18834 (18.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 658  bytes 57212 (55.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 658  bytes 57212 (55.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost yum.repos.d]# service network status
Configured devices:
lo ens33
Currently active devices:
lo ens33
[root@localhost yum.repos.d]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.43  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::20c:29ff:fe3d:f8fa  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:3d:f8:fa  txqueuelen 1000  (Ethernet)
        RX packets 272  bytes 27076 (26.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 56  bytes 6948 (6.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 662  bytes 57632 (56.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 662  bytes 57632 (56.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost yum.repos.d]#




[root@localhost ~]# yum search mariadb

Install db packages

[root@localhost ~]# yum install mariadb mariadb-server

enable to available upon reboot

[root@localhost ~]# systemctl enable mariadb
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
[root@localhost ~]# ls -l /usr/lib/systemd/system/mariadb.service /etc/systemd/system/multi-user.target.wants/mariadb.service
lrwxrwxrwx. 1 root root   39 Jan  6 22:58 /etc/systemd/system/multi-user.target.wants/mariadb.service -> /usr/lib/systemd/system/mariadb.service
-rw-r--r--. 1 root root 1697 Nov 17 07:28 /usr/lib/systemd/system/mariadb.service
[root@localhost ~]#

[root@localhost ~]# systemctl status mariadb
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)
   Active: inactive (dead)

[root@localhost ~]#

[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl status mariadb
mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)
   Active: active (running) since Tue 2015-01-06 23:00:46 EST; 4s ago



[root@localhost ~]# mysql_secure_installation
/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@localhost ~]# firewall-c
firewall-cmd     firewall-config
[root@localhost ~]# firewall-cmd --permanent --add-service==mysql
Error: INVALID_SERVICE: =mysql
[root@localhost ~]# firewall-cmd --permanent --add-service=mysql
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]#





[root@localhost ~]# mysql --user=jay mysql
ERROR 1045 (28000): Access denied for user 'jay'@'localhost' (using password: NO)
[root@localhost ~]# mysql --user=root mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)


[root@localhost ~]# mysqladmin -u root password abc1234
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
[root@localhost ~]# /etc/init.d/mysql stop
-bash: /etc/init.d/mysql: No such file or directory


[root@localhost ~]# systemctl stop mariadb
[root@localhost ~]# mysqld
mysqld_multi   mysqld_safe    mysqldump      mysqldumpslow
[root@localhost ~]# mysqld_safe --skip-grant-tables &
[1] 14614
[root@localhost ~]# 150106 23:37:14 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
150106 23:37:14 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@localhost ~]# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.40-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('peacesoul') WHERE User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3  Changed: 0  Warnings: 0

MariaDB [(none)]>


[root@localhost ~]# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.40-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('peacesoul') WHERE User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3  Changed: 0  Warnings: 0

MariaDB [(none)]> use test
Database changed
MariaDB [test]> create database sama_data
    -> ;
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sama_data          |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [test]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> create database suvidb
    -> ;
Query OK, 1 row affected (0.00 sec)

MariaDB [mysql]> show datbases;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'datbases' at line 1
MariaDB [mysql]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sama_data          |
| suvidb             |
| test               |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [mysql]>


[root@localhost ~]# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.40-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> UPDATE mysql.user SET Password=PASSWORD('peacesoul') WHERE User='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3  Changed: 0  Warnings: 0

MariaDB [(none)]> use test
Database changed
MariaDB [test]> create database sama_data
    -> ;
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sama_data          |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [test]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> create database suvidb
    -> ;
Query OK, 1 row affected (0.00 sec)

MariaDB [mysql]> show datbases;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'datbases' at line 1
MariaDB [mysql]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sama_data          |
| suvidb             |
| test               |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [mysql]>




[root@localhost ~]# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.40-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sama_data          |
| suvidb             |
| test               |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> use suvidb
Database changed
MariaDB [suvidb]> create table employee (
    -> tid bigint not null auto_increment,
    -> fname varchar(100) not null,
    -> lname varchar(100) not null,
    -> city text not null,
    -> primary key(tid),
    -> index ix_fname_tid (fname, tid)
    -> ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.10 sec)

MariaDB [suvidb]> show create table employee;
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                                                                                                       |
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| employee | CREATE TABLE `employee` (
  `tid` bigint(20) NOT NULL AUTO_INCREMENT,
  `fname` varchar(100) NOT NULL,
  `lname` varchar(100) NOT NULL,
  `city` text NOT NULL,
  PRIMARY KEY (`tid`),
  KEY `ix_fname_tid` (`fname`,`tid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+----------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [suvidb]> desc employee;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| tid   | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| fname | varchar(100) | NO   | MUL | NULL    |                |
| lname | varchar(100) | NO   |     | NULL    |                |
| city  | text         | NO   |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
4 rows in set (0.03 sec)

MariaDB [suvidb]> create table test1 (field1 int, field2 enum('red', 'green'));
Query OK, 0 rows affected (0.00 sec)

MariaDB [suvidb]> desc test1
    -> ;
+--------+---------------------+------+-----+---------+-------+
| Field  | Type                | Null | Key | Default | Extra |
+--------+---------------------+------+-----+---------+-------+
| field1 | int(11)             | YES  |     | NULL    |       |
| field2 | enum('red','green') | YES  |     | NULL    |       |
+--------+---------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

MariaDB [suvidb]> alter online table test1 modify field2 enum('red','green','blue');
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [suvidb]> alter online table test1 add field3 int;
ERROR 1915 (HY000): Can't execute the given 'ALTER' command as online
MariaDB [suvidb]>



MariaDB [suvidb]> alter online table test1 add field3 int;
ERROR 1915 (HY000): Can't execute the given 'ALTER' command as online
MariaDB [suvidb]> alter table test1 add created datetime not null;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [suvidb]> alter table test1 add index ix_created (created);
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [suvidb]> desc test1;
+---------+----------------------------+------+-----+---------+-------+
| Field   | Type                       | Null | Key | Default | Extra |
+---------+----------------------------+------+-----+---------+-------+
| field1  | int(11)                    | YES  |     | NULL    |       |
| field2  | enum('red','green','blue') | YES  |     | NULL    |       |
| created | datetime                   | NO   | MUL | NULL    |       |
+---------+----------------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

MariaDB [suvidb]>


MariaDB [suvidb]> create table tab_test (
    -> fd1 int not null,
    -> fd2 varchar(50),
    -> primary key(fd1)) engine=innodb;
Query OK, 0 rows affected (0.01 sec)

MariaDB [suvidb]> insert into tab_test (fd1, fd2) values (1, 'John');
Query OK, 1 row affected (0.00 sec)

MariaDB [suvidb]> insert into tab_test values (2, 'Mark');
Query OK, 1 row affected (0.01 sec)

MariaDB [suvidb]> insert into tab_test(fd1, fd2)
    -> values (3, 'Bill') on duplicate key update fd2='Bill';
Query OK, 1 row affected (0.00 sec)

MariaDB [suvidb]> insert into tab_test(fd1, fd2)
    -> values (3, 'RamSing') on duplicate key update fd2='RamSing';
Query OK, 2 rows affected (0.00 sec)

MariaDB [suvidb]> select * from tab_test;
+-----+---------+
| fd1 | fd2     |
+-----+---------+
|   1 | John    |
|   2 | Mark    |
|   3 | RamSing |
+-----+---------+
3 rows in set (0.00 sec)

MariaDB [suvidb]>


MariaDB [suvidb]> select * from tab_test\G;
*************************** 1. row ***************************
fd1: 1
fd2: John
*************************** 2. row ***************************
fd1: 2
fd2: Mark
*************************** 3. row ***************************
fd1: 3
fd2: RamSing
3 rows in set (0.00 sec)

ERROR: No query specified

MariaDB [suvidb]>


MariaDB [suvidb]> update tab_test set fd2='Brian' where fd1=1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [suvidb]> select * from tab_test where fd1=1;
+-----+-------+
| fd1 | fd2   |
+-----+-------+
|   1 | Brian |
+-----+-------+
1 row in set (0.02 sec)

MariaDB [suvidb]> select * from tab_test where fd1=1
    -> ;
+-----+-------+
| fd1 | fd2   |
+-----+-------+
|   1 | Brian |
+-----+-------+
1 row in set (0.00 sec)

MariaDB [suvidb]> update tab_test set fd2='brian';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

MariaDB [suvidb]> select * from tab_test;
+-----+-------+
| fd1 | fd2   |
+-----+-------+
|   1 | brian |
|   2 | brian |
|   3 | brian |
+-----+-------+
3 rows in set (0.00 sec)

MariaDB [suvidb]> replace tab_test set fd1=1, fd2='Matt';
Query OK, 2 rows affected (0.00 sec)

MariaDB [suvidb]> select * from tab_test where fd1=1;
+-----+------+
| fd1 | fd2  |
+-----+------+
|   1 | Matt |
+-----+------+
1 row in set (0.00 sec)

MariaDB [suvidb]> delete from tab_test where fd1=1;
Query OK, 1 row affected (0.00 sec)

MariaDB [suvidb]> select * from tab_test;
+-----+-------+
| fd1 | fd2   |
+-----+-------+
|   2 | brian |
|   3 | brian |
+-----+-------+
2 rows in set (0.00 sec)

MariaDB [suvidb]>

No comments:

Post a Comment