Categories
Databases

Mysql common questions and answers

CREATE USER

CREATE USER ‘jeffrey’@’localhost’ IDENTIFIED BY ‘mypass’;

Create user without password.

CREATE USER ‘jeffrey’@’localhost’;

DROP User

DROP USER ‘jeffrey’@’localhost’;

GRANT

Steps:

CREATE USER ‘jeffrey’@’localhost’ IDENTIFIED BY ‘mypass’;

GRANT ALL ON db1.* TO ‘jeffrey’@’localhost’;

GRANT SELECT ON db2.invoice TO ‘jeffrey’@’localhost’;

GRANT USAGE ON *.* TO ‘jeffrey’@’localhost’ WITH MAX_QUERIES_PER_HOUR 90;

RENAME USER

RENAME USER ‘jeffrey’@’localhost’ TO ‘jeff’@’127.0.0.1’;

SET PASSWORD

SET PASSWORD FOR ‘bob’@’%.loc.gov’ = PASSWORD(‘newpass‘);

Or

UPDATE mysql.user SET Password=PASSWORD(‘newpass‘)

WHERE User=’bob’ AND Host=’%.loc.gov’;

FLUSH PRIVILEGES;

Or

GRANT USAGE ON *.* TO ‘bob’@’%.loc.gov’ IDENTIFIED BY ‘newpass‘;

MYSQLDUMP BACKUP

Syntax:

shell> mysqldump [options] db_name [tbl_name ...]

shell> mysqldump [options] --databases db_name ...

shell> mysqldump [options] --all-databases

examples:

mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

MYSQLDUMP RESTORE

Syntax:

mysql db_name < script.sql > output.tab

Examples:

mysql -u root -p[root_password] [database_name] < dumpfilename.sql

RECOVER/RESET mysql root password.

·Stop mysql service

#/etc/init.d/mysql stop

·Start mysql server w/o password

#mysqld_safe –skip-grant-tables &

·Connect to mysql server using mysql client

# mysql -u root

·Setup new password for mysql root user

mysql> use mysql; mysql> update user set password=PASSWORD(“NEW-ROOT-PASSWORD”) where User=’root’; mysql> flush privileges; mysql> quit

·Stop mysql server.

/etc/init.d/mysql stop

·Start server in normal mode & test

# /etc/init.d/mysql start # mysql -u root -p

Categories
Linux Interview questions

Linux interview questions

Q: How are device files represented in UNIX/Linux?

A: All devices  are represented as files  called special files and are located in the /dev directory.

Q: What is a inode?

The inode(Index node) is a fundamental concept in Linux/Unix file systems. Each object in the file system  is represented by an inode. Each and every file in Linux/Unix file systems has the following attributes.

File type (executable, block, special etc)

Permissions (read, write etc)

Owner

Group

File size

File access, change, modification time, file deletion time

Extended attribute information such as append only or no one can delete file including root user (immutability)

Access control lists (ACL)

All the above information are stored in an Inode. Each inode is identified by a unique inode number within the file system.

Q: how can I see an inode no?

A:  # ls –i /etc/passwd

Output: 32820 /etc/passwd

We can use the ‘stat’ command to find out inode number and it’s attributes.

What are the process states in unix/linux?

Process states in Linux are below

Running:  process is running or ready to run.

Interruptible: a Blocked state of a process and waiting for an event or signal from another process

Uninterruptible: a blocked state. Process waits for a hardware condition and cannot handle any signal

Stopped: Process is stopped or halted and can be restarted by some other process

Zombie: process terminated, but information is still there in the process table.

Q: Command  used to remove password assigned to a group?

Gpasswd -r

 Q: How to find what shell we are using ?

Echo $SHELL

 Q: How to find files which have been accessed within the last 30 days?

Find / -type f  -atime -30 > output.txt

“-30” means that it was modified “less than 30 days ago”
“+30” means that it was modified “more than 30 days ago”

For modified we can use “mtime”

 Q: What is a zombie?

process terminated, but information is still there in the process table

Q: How do I find a zombie process

A: use ‘top’ or ‘ps’

a process with Z  is a Zombie process and it can be killed using “kill -9 <process id>”

 Q: Which daemon is responsible for tracking events in the system?

Syslogd

 Q: What is the role of a /boot directiory?

This directory has files related to the system bootloader (grub/lilo)

Given a typical CentOS or Fedora host, you will probably see something similar to the following in /boot:

cd /boot

tree

.

|– System.map-2.6.29.5-191.fc11.x86_64

|– System.map-2.6.30

|– config-2.6.29.5-191.fc11.x86_64

|– config-2.6.30

|– efi

|   `– EFI

|       `– redhat

|           `– grub.efi

|– grub

|   |– device.map

|   |– e2fs_stage1_5

|   |– fat_stage1_5

|   |– ffs_stage1_5

|   |– grub.conf

|   |– iso9660_stage1_5

|   |– jfs_stage1_5

|   |– menu.lst -> ./grub.conf

|   |– minix_stage1_5

|   |– reiserfs_stage1_5

|   |– splash.xpm.gz

|   |– stage1

|   |– stage2

|   |– ufs2_stage1_5

|   |– vstafs_stage1_5

|   `– xfs_stage1_5

|– initrd-2.6.29.5-191.fc11.x86_64.img

|– initrd-2.6.30.img

|– vmlinuz-2.6.29.5-191.fc11.x86_64

`– vmlinuz-2.6.30

For each kernel release, you will typically see a vmlinuz, System.map, initrd and config file. The vmlinuz file contain the actual Linux kernel, which is loaded and executed by grub. The System.map file contains a list of kernel symbols and the addresses these symbols are located at. The initrd file is the initial ramdisk used to preload modules, and contains the drivers and supporting infrastructure (keyboard mappings, etc.) needed to manage your keyboard, serial devices and block storage early on in the boot process. The config file contains a list of kernel configuration options, which is useful for understanding which features were compiled into the kernel, and which features were built as modules.