• Skip to main content

Uly.me

cloud engineer

  • Home
  • Archives
  • Search

Archives for November 2020

MySQL Read Only

November 30, 2020 by Ulysses

If you need to perform backup or replicate a database, you can lock up the database by doing a global read block to make it read-only.

The process is:

  1. Make the server read-only, so that it processes only retrievals and blocks updates.
  2. You can then perform the backup.
  3. Change the server back to its normal read/write state.

Read only.

FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = ON;

FLUSH TABLES WITH READ LOCK; SET GLOBAL read_only = ON;

Back to normal mode.

SET GLOBAL read_only = OFF;
UNLOCK TABLES;

SET GLOBAL read_only = OFF; UNLOCK TABLES;

You can run these MySQL commands within MySQL or via a bash terminal. Check out my previous post.

Filed Under: Cloud, Linux Tagged With: global, mysql, read-only

Running MySQL commands from the Terminal

November 29, 2020 by Ulysses

You can run MySQL commands from the terminal by using -e switch. Here are a few examples.

mysql -u username -p -e "create database mydb"
mysql -u username -p -e "use mydb"
mysql -u username -p database -e "select * from mytable"

mysql -u username -p -e "create database mydb" mysql -u username -p -e "use mydb" mysql -u username -p database -e "select * from mytable"

If you have .mycnf configured, you can omit the username and password.

mysql -e "create database mydb"
mysql -e "use mydb"
mysql -e "select * from mytable"

mysql -e "create database mydb" mysql -e "use mydb" mysql -e "select * from mytable"

To run multiple commands from a single line, separate the commands using a semicolon.

mysql -e "create database somedb; use mydb; select * from mytable;"

mysql -e "create database somedb; use mydb; select * from mytable;"

Filed Under: Linux Tagged With: commands, mysql, run, terminal

Change MySQL User Password

November 29, 2020 by Ulysses

This is a very simple command to run. Login to MySQL first and run the following the command line.

ALTER USER username IDENTIFIED BY 'password';

ALTER USER username IDENTIFIED BY 'password';

Flush privileges for changes to take effect.

flush privileges;

flush privileges;

Filed Under: Linux Tagged With: alter, change, mysql, password, user

WordPress Read Only

November 29, 2020 by Ulysses

Here’s how to create a WordPress site that’s read only. You will not be able to create, update and delete posts.

  1. Login to MySQL or MariaDB.
  2. Choose mysql database.
  3. Create a new user called ‘wpro’ for WordPress read only.
  4. Grant select permissions to all tables in ‘wordpress’ database.
  5. Flush privileges to commit your changes.
mariadb -u root -p
use mysql;
create user 'wpro'@'localhost' identified by 'yourpassword';
grant select on wordpress.* to 'wpro'@'localhost';
flush privileges;

mariadb -u root -p use mysql; create user 'wpro'@'localhost' identified by 'yourpassword'; grant select on wordpress.* to 'wpro'@'localhost'; flush privileges;

In MySQL or MariaDB, you have to terminate all commands with a semicolon.

Now edit your WordPress wp-config.php file. vim /var/www/wordpress/wp-config.php.

/** MySQL database username */
define('DB_USER', 'wpro');
 
/** MySQL database password */
define('DB_PASSWORD', 'yourpassword');

/** MySQL database username */ define('DB_USER', 'wpro'); /** MySQL database password */ define('DB_PASSWORD', 'yourpassword');

After saving the wp-config.php file, everything should work just like before, except that you will not be able to save, publish or delete posts, pages, or add or delete media files to your WordPress site. It’s working as intended.

Filed Under: Linux, WP Tagged With: create, grant, mariadb, mysql, read-only, select, user

Copy A Symbolic Link

November 27, 2020 by Ulysses

Here’s how to copy a symbolic link which is also known as a soft link from one directory to another. A regular copy command will not work. You will need to use the -P option to copy the symbolic link from one directory to another. If omitted, the symbolic links will not be copied.

cp -P /directory1/* /directory2/

cp -P /directory1/* /directory2/

How to create a symbolic link.

ln -s sourcefile myfile
ln -s /path/to/file myfile

ln -s sourcefile myfile ln -s /path/to/file myfile

Here are the man pages for ln and for cp.

Filed Under: Linux Tagged With: copy, cp, create, link, ln, symbolic

Check Network Promiscuous Mode

November 23, 2020 by Ulysses

Promiscuous mode is a mode for a network interface where the controller to passes all traffic it receives to the CPU instead of passing the frames to the controller. This is helpful if you want to capture all traffic as part of troubleshooting. The question is, how can you tell if your network interface is in a promiscuous mode? Here’s a couple of commands.

Here’s the default mode.

sudo ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff

sudo ip link show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff

Here’s promiscuous mode. Look for PROMISC.

sudo ip link show eth0
2: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1460 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff

sudo ip link show eth0 2: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1460 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff

The other command is netstat. Look for P flag.

netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1460 21895816      0      0 0      22645756      0      0      0 BMPRU
lo              65536    44129      0      0 0         44129      0      0      0 LRU

netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg eth0 1460 21895816 0 0 0 22645756 0 0 0 BMPRU lo 65536 44129 0 0 0 44129 0 0 0 LRU

Finally, if you want to enable promiscuous mode, run one of these commands.

sudo ip link set eth0 promisc on
ifconfig eth0 promisc

sudo ip link set eth0 promisc on ifconfig eth0 promisc

To disable, use ifconfig.

ifconfig eth0 -promisc

ifconfig eth0 -promisc

Filed Under: Linux Tagged With: ip, link, netstat, promiscuous mode, show

iotop

November 22, 2020 by Ulysses

iotop is a Linux command similar to top but instead of CPU and memory it will display and monitor your disk IO usage.

To install, run the following command based on your Linux ditro.

yum install iotop
apt install iotop
dnf install iotop

yum install iotop apt install iotop dnf install iotop

To use.

iotop
iotop -o

iotop iotop -o

Output:

Filed Under: Linux Tagged With: disk, io, iotop, top, usage

MySQL Read Only

November 22, 2020 by Ulysses

Here’s how to make a MySQL database read only.

mysql> FLUSH TABLES WITH READ LOCK;
mysql> SET GLOBAL read_only = ON;

mysql> FLUSH TABLES WITH READ LOCK; mysql> SET GLOBAL read_only = ON;

It’s very useful if creating a replica database.

Filed Under: Linux Tagged With: mysql, read-only

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to Next Page »
  • Home
  • About
  • Contact

Copyright © 2022