I had a problem with my hdd. There is a new system running in place and I found that I can mount and access the / of my old hdd (It had a Debian Linux distribution). However I forgot to backup some important data in the DB tables and I was wondering if there was anyway to execute a mysql server command from the mysql server installation in the mounted drive?
If your hdd contains complete OS, you can simply mount it and chroot to it. In chrooted environment start your mysql server and take data-backup with mysqldump command.
Or you can simply install mysql-server on your new system, change data directory option in /etc/my.cnf to the mounted partition, backup the data with mysqldump command. You can then revert the my.cnf change back.
Related
Copying database backup files from xamp/mysql/data of windows to linux in path /var/lib/mysql, but it is creating only empty database in phpmyadmin of linux.
Please some one help me to solve this issue, i have only these files backup with me
The best way is-
Step1: Take backup from windows by mysqldump-
mysqldump -uroot -proot123 -A > backup.sql
Step2: Move this backup to linux, you can use winscp tool for it.
Step3: Now restore this backup to linux machine.
mysql -uroot -proot123 < backup.sql
Modification:
It seems your db engine is myisam and you just coppied file/folder from window to linux, so give permissions as per below-
chown -R mysql.mysql /var/lib/mysql
First create a .my.cnf file containing the mysql root password in your users home folder, on linux.
On windows, there exists a .my.ini or something which serves the same purpose. That way you will not have to reenter your passwords a lot during the next steps, which you are very likely to repeat several times until you get them right, I fear. :)
Since unix/linux and windows have different ways to save files, you might very likely run into errors during a simple copy-restore process, depending on how you copy files.
Your best bet is likely copying the original mysql folders to another windows machine and save them accordingly, such that mysql can find them. (With an installed mysql instance, of course.) I don't know what else you might need, if the databases are not found instantly, since I never had to do this prior and have no test setup here to check this case out.
When the databases are found through the mysql on the WINDOWS server, from the mysql cli prompt there look up which encoding etc the db uses:
SELECT SCHEMA_NAME 'database', default_character_set_name 'charset', DEFAULT_COLLATION_NAME 'collation' FROM information_schema.SCHEMATA;
Then create a new database on the LINUX server with the same name and the same encoding's from MYSQL CLI:
create database <db-name> character set <charset> collate <collation>;
Then on the WINDOWS server in a CMD window, do a mysqldump which should look familiar on windows like on linux:
mysqldump <db-name> > <db-name>.sql
Then copy the dump over to the LINUX server and replay it:
mysql <db-name> < <db-name>.sql
Afterwards you will have to recreate a user (if you know which user and password your web app used to access the database, create a new user with these credentials and grant him full access on your database.
If you do not happen to know the credentials anymore, create an arbitrary user and then change the database credentials in the configfile of your web application.
In case you have problems, check the unix file permissions of the files you copied, such that mysql can access them.
Good luck, mate.
I want to change the default port number of MySQL server presently it is 3306. I want to change it to 3360.
I have tried:
-- port=3360
But things are not working for me. Please provide query to change port not any configuration. I am using Windows 8 64 bit.
You need to edit your my.cnf file and make sure you have the port set as in the following line:
port = 3360
Then restart your MySQL service and you should be good to go. There is no query you can run to make this change because the port is not a dynamic variable (q.v. here for MySQL documentation showing a table of all system variables).
If you're on Windows, you may find the config file my.ini it in this directory
C:\ProgramData\MySQL\MySQL Server 5.7\
You open this file in a text editor and look for this section:
# The TCP/IP Port the MySQL Server will listen on
port=3306
Then you change the number of the port, save the file.
Find the service MYSQL57 under Task Manager > Services and restart it.
On newer (for example 8.0.0) the simplest solution is (good choice for a scripted start-up for example):
mysqld --port=23306
When server first starts the my.ini may not be created where everyone has stated. I was able to find mine in C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6
This location has the defaults for every setting.
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
# pipe
# socket=0.0
port=4306 !!!!!!!!!!!!!!!!!!!Change this!!!!!!!!!!!!!!!!!
[mysql]
no-beep
default-character-set=utf8
Go to installed mysql path and find bin folder,open my.ini and search 3306 after that change 3306 to 3360
Actually, you can just run the service using /mysqld --PORT 1234, it would force mysql to run on the specified port without change the cnf/ini file.
I just cought a case that cnf didn't work. It was weired... so I just use the cmd line as the shortcut and it works!
try changing the connection port to 8012
open xampp as administrator
Mysql config => my.ini change the port from 3306 to 8012
close and run it again
I hope it will work.
If you are using windows and installed the database as a service, which is the default, you should find your configuration file by opening your services management console.
For instance: win + r and then type services.msc
Look for a service called MySQL or MariaDB.
On the general tab of the properties of this service you can find a path to your mysqld.exe file and the arguments to start the exe. The --defaults-file argument should point to your configuration file.
Edit your configuration file and restart the MySQL service.
In Windows 8.1 x64 bit os, Currently I am using MySQL version :
Server version: 5.7.11-log MySQL Community Server (GPL)
For changing your MySQL port number, Go to installation directory, my installation directory is :
C:\Program Files\MySQL\MySQL Server 5.7
open the my-default.ini Configuration Setting file in any text editor.
search the line in the configuration file.
# port = .....
replace it with :
port=<my_new_port_number>
like my self changed to :
port=15800
To apply the changes don't forget to immediate either restart the MySQL Server or your OS.
Hope this would help many one.
Change my.cnf file and add this line or change it port=3360
at my fedora 34
sudo vi /etc/my.cnf
add This line ==> port=3360
The best way to do this is take backup of required database and reconfigure the server.
Creating A Backup
The mysqldump command is used to create textfile “dumps” of databases managed by MySQL. These dumps are just files with all the SQL commands needed to recreate the database from scratch. The process is quick and easy.
If you want to back up a single database, you merely create the dump and send the output into a file, like so:
mysqldump database_name > database_name.sql
Multiple databases can be backed up at the same time:
mysqldump --databases database_one database_two > two_databases.sql
In the code above, database_one is the name of the first database to be backed up, and database_two is the name of the second.
It is also simple to back up all of the databases on a server:
mysqldump --all-databases > all_databases.sql
After taking the backup, remove mysql and reinstall it. After reinstalling with the desired port number.
Restoring a Backup
Since the dump files are just SQL commands, you can restore the database backup by telling mysql to run the commands in it and put the data into the proper database.
mysql database_name < database_name.sql
In the code above, database_name is the name of the database you want to restore, and database_name.sql is the name of the backup file to be restored..
If you are trying to restore a single database from dump of all the databases, you have to let mysql know like this:
mysql --one-database database_name < all_databases.sql
I want to move my mysql database from rackspace server to aws server.Is there any way to do it easily.It contains more or less 1 million rows of data
If your site is not a live site and downtime is not an issue, you can try the below
#step1: take a dump of your db
>mysqldump –-user root –-password=myrootpassword db_test > db_test.sql
#step2: zip the .sql file - this is optional
>gzip db_test.sql
#step3: transfer the file to AWS using .pem file
>scp -i myAmazonKey.pem db_test.sql.gz ec2-user#<ur_ip_address>:~/.
#step4: login to your AWS instance
#step5: unzip the file
>gunzip db_test.sql.gz
#step6: import the db to your AWS mysql instance
>mysql -u username -p password db_name < db_test.sql
Please go through the below steps,
Old Server
Stop mysql server
Copy contents of datadir to another location on disk (~/mysqldata/*)
Start mysql server again (downtime was 10-15 minutes)
compress the data (tar -czvf mysqldata.tar.gz ~/mysqldata)
copy the compressed file to new server
New Server
install mysql (don't start)
unzip compressed file (tar -xzvf mysqldata.tar.gz)
move contents of mysqldata to the datadir
Make sure your innodb_log_file_size is same on new server, or if it's not, don't copy the old log files (mysql will generate these)
Start mysql
Heres the deal. Removed mysql 5.0.xx and neglected to dump a data folder which is on a mounted drive.
I have mySql 5.6.5 now installed and running and the data folder works fine in the default directory. I attempted to switch the data dir in the my.conf file but that results in the error "The server quit without updating PID file."
What I would like to do is still have my.conf point at the default data directory while also adding the external database to MySQL. This is how I had it set up in mySql 5.0.xx. The only problem is I created the database via a GUI and specified that the data would actually be stored in the mounted drive. I can't quite figure out how to do this via the command line and I have found no good sources of documentation or examples.
You probably created a symbolic link to the directory on the mounted drive. This is done with the ln command:
cd /var/lib/mysql
ln -s /mounted_drive/data_directory/db_name db_name
On Ubuntu the MySQL data folder resides in /var/lib
Generally you can set this variable in my.cnf http://dev.mysql.com/doc/refman/5.6/en/server-options.html#option_mysqld_datadir in order to change the default data directory.
My server recently crashed and I have backed the Mysql files using raid.
BACKED UP DIRECTORY
/backup/var/lib/mysql
I installed new OS(RHEL5.3) to my server and I want to restore my DB to MySQL
How do I do this?
I know you can ssh mysql > the dump files
but, these backed up files are not in DUMP.
They are separated as .MYD .MYI .frm etc..
I guess your backup file is not in the same server as your database.
Try:
scp -r /backup/var/lib/mysql/* DB_SERVER:YOUR_NEW_DATABASE_DIRECTORY
Then
ssh DB_SERVER
.. restart your mysql daemon (easier)
.. or flush privileges, flush tables ...
Copy these files directly to your mysql data directory, and you will be able to access them in MySQL. That should help you!