Running MySQL from a virtual server with database on the host disk - mysql

I'm trying to set up MySQL running in a virtual server (CentOS 6), but as disk intensive stuff isn't great on a VM, I intend to store the database on the host (KVM on CentOS 6) server, and connect to it via Samba or NFS, or the like.
The trouble is that MySQL doesn't seem to like the /var/lib/mysql directory being mounted from a network drive, and I'm getting various different errors in the various configurations I've tried.
My end game is to have the DB server on a VM that can be easily moved between hosts, and the data on a redundant (probably clustered) server. In the mean time, the storage area I'm using on the host server is mirrored using DRBD.
Has anyone done something similar, and can suggest a config that works, or an altogether better way of doing it?

Using a file level protocol is a really bad idea. They are designed to do a very different job.
For block device level protocols there's 2 choices (DRBD doesn't apply here). AoE or iSCSI. IIRC, AoE is tightly coupled to physical network interfaces which may cause some complications in your setup - hence I'd recommend having a long hard look at iSCSI.

Related

Can we set 2 different port for apache mysql port?

The default port for MySQL connection is 3306. But can we set 2 different port for it? Maybe port 30 and 3306, thus we can have connections at localhost:30 and localhost:3306, assuming all ports are free. I try to run this using xampp in window 10.
It is not recommend by mysql for good reasons.
>
Warning
Normally, you should never have two servers that update data in the same databases. This may lead to unpleasant surprises if your operating system does not support fault-free system locking. If (despite this warning) you run multiple servers using the same data directory and they have logging enabled, you must use the appropriate options to specify log file names that are unique to each server. Otherwise, the servers try to log to the same files.
Even when the preceding precautions are observed, this kind of setup works only with MyISAM and MERGE tables, and not with any of the other storage engines. Also, this warning against sharing a data directory among servers always applies in an NFS environment. Permitting multiple MySQL servers to access a common data directory over NFS is a very bad idea. The primary problem is that NFS is the speed bottleneck. It is not meant for such use. Another risk with NFS is that you must devise a way to ensure that two or more servers do not interfere with each other. Usually NFS file locking is handled by the lockd daemon, but at the moment there is no platform that performs locking 100% reliably in every situation.
https://dev.mysql.com/doc/refman/8.0/en/multiple-data-directories.html
See here there you will find also, what you have to do

Applications downs due to heavy MySQL server load

We have a 2GB Digital Ocean server, and it is dedicated for a MySQL server of other two PHP servers. we are using Percona MySQL Server 5.6 on this server. We configured MySQL replication and these configuration is working fine
Our issue is sometime our site monitoring tools reporting that some of the URL hosted with this server is down (May be this is happening once in a week or two). When I am checking, I could see that Mysql Master server load is too much high (May be 35 - 40), so the MySQL server was not responded. # that I usually do a MySQl service restart, this restart cause to server load become normal and the sites started working after service restart.
This is a back-end MySQL database server of 20-25 PHP applications (WordPress, Drupal and some custom applications server).
Here are my questions,
Why this server load automatically goes down, after a spikes happens?
Is there any way in which database is causing issues? So that I can identify the application too.
How can I identify the root cause of this issues
Depending upon your working dataset, a 2GB server providing access for 20-25 PHP applications (WordPress, Drupal and some custom applications server) could be the issue.
For example, if you have a 1.4GB buffer pool (assuming all tables are InnnoDB) and 10GB of data, then your various applications could end up competing for resources, such as I/O, buffer pool pages, Adaptive Hash Index, query cache. They could also, assuming caching is used, be invalidating theit caches within a similar timeframe, thus sending expensive queries to the database.
Whilst a load of 50 is something that you would normally want to avoid, the load average is not something that you should concern yourself with if showing in isolation.
The use of the uninterruptible state has since grown in the Linux
kernel, and nowadays includes uninterruptible lock primitives. If the
load average is a measure of demand in terms of running and waiting
threads (and not strictly threads wanting hardware resources), then
they are still working the way we want them to.
http://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html
If the issue is happening once per week then it is starting to sound like a batch process, or cache expiration issue - too much happening at once for the resources available.
The best thing to do is to monitor and look for the cause. Since you are already using Percona Server, using PMM should give you the perfect insight to find the cause, although it works with Oracle MySQL, MariaDB, Aurora, etc. You can try a demo to see the insights that you can gain:
https://pmmdemo.percona.com. The software is Open Source and free to use.
You can look in QAN to find the most expensive queries, whilst looking at Prometheus data to give an insight into the host itself. There are some recommendations to get the most from PMM, depending upon your flavour of MySQL.

MySQL configuration type?

I am installing MySQL and when it reaches the configuration step it is asking me to select from on of the following server configuration types:
Development Machine
Server Machine
Dedicated Machine
I am new to mysql, the reason I am installing this is because I am making an application which will store data on a database using MySQL. Now, can someone explain what does these server configurable type mean and which one should I be selecting?
This is only about setting up the initial my.cnf file. You can always change this later.
Generally server configurations allocate a lot more memory to MySQL than you would on your development machine.
This is basically trying to pick the default memory use setting and configuration (over simplification, but good enough for now). If its on a shared system or you have no idea of the physical machine, start with development.
You can always edit the my.cnf to better optimize your setup

Can a RDBMS have its datadir on another machine

I am playing with mysql and the command select ##datadir; has got me thinking.For someone like me without the means to have a dedicated server i am relegated to cheap vps's which are no good since once my disk space quota is consumed,there is no adjusting my quota upwards.
Since a new connection would be a new thread,i imagine it would be convinient to have some form of network multithreading with my datadir sitting at dropbox or google.is there a database system which allow one access a datadir across a network?.
The MySQL database requires a directory path.
You could fool it to use NFS. However, be warned that "standard" linux NFS is not a very good solution: it introduces locks which may lead to lockdown of database (experienced).
Otherwise some storage devices provide with their own NFS clients.
Or you could use SAN/NAS/Whatever. I would further suggest that what you may be looking for is a separate storage device, not a separate "machine".

Using 2 servers for MySQL

I have 2 servers for my website
Web Server
For sending dynamic content, mostly created with PHP
A lot of RAM and a fast processor, only a few GBs of hard drive space.
and a
File Server
For sending static content, images, videos etc..
A few TBs of hard drive space, not as much RAM and a slower processor.
I want to Use the speed of the Web Server, but the space of the File Server. But I heard the overhead of NFS will make it so slow it will not matter...
I will be using MySQL and I want to know how I should optimize the database so I can keep the data on the File Server, but have the queries preformed, and processed by the Web Server.
The advice you received is correct in my experience... running mysqld on one box and using a remote server via NFS for file storage is not very fast (if the remote storage were a SAN that would be a different matter).
You can reduce the number of times your database is hit and leverage the RAM on the web server by caching on that tier. Look into introducing something like memcached to help with the most expensive MySQL operations.
If some of your tables are small but used frequently, you could consider running a second instance of MySQL on your web server just for those tables. Keep in mind, though, that you will have two separate points of database failure that need to be managed (appropriate backups, security updates, etc.).