Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Tuesday, December 2, 2014

Mysql: execute sql file from command line.

If you need to execute some commands from command line,as in this case, all stored into a .sql file give this:

> mysql -u _your_username_ -p

after inserted the password

> use _your_database_ ;

(in case of your_database is not existent remember to create it before. )
then

> source /home/_your_userhome_/_your_file.sql


Bye....

Mysql: quick backup with mysqldump

You need to do a quick backup of a mysql table?
Give this command:

mysqldump database_to_backup_name -u root -p > ./filename_with_dumped_db.sql

this will produce a file(filename_with_dumped_db.sql) with all the backupped db(database_to_backup_name).

Please refer here to the mysql manual pages.

Bye..

Thursday, September 1, 2011

MySQL: install as deamon, for start/stop at system startup/shutdown (under CentOS 5.6 64 bit)

Go under mysql execution commands directory....:
cd /usr/bin/
Create startupMysql.sh file with the follow code:
#!/bin/bash
/etc/init.d/mysqld start
Create shutdownMysql.sh file with the follow code:
#!/bin/bash
/etc/init.d/mysqld stop
Give to them the execution privileges only for root
chmod 700 startupMysql.sh
chmod 700 shutdownMysql.sh
Choose the your "favourite" rcXXX.d directory (depends to your configuration)
to put into your deamon startup/shutdown commands.
I choose rc5.d, so:
cd /etc/rc5.d
and give the following ln -s commands:
ln -s /usr/bin/startup_mysqld.sh S100startupMysql
ln -s /usr/bin/shutdown_mysqld.sh K100shutdownMysql
Your deamon startup/shutdown commands are done well...
Now clean up the mysql log file(you find it into /etc/my.cnf), usually /var/log/mysqld.log
cd /var/log
echo "" > mysqld.log
to check, if at the system restart, you mysql restart too.
Restart the system.....:
shutdown -r now

Byw


MySQL installation and configuration under CentOS 5.6 64-bit

We have to search the name ho the packet to install....
yum search mysql
For my distribution the packet name mysql-server.x86_64
so do:
yum install mysql-server.x86_64
At installation completed, mysql is without password, and is down.
So startup the mysql
service mysqld start
so give the following command to reset password
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE user='root';
and
flush privileges;
to runtime flush up the executed command.
Give exit to logout to the mysql connection and test new root account logging in with the new credentials:
mysql -uroot -p

Bye

Thursday, August 25, 2011

MySql: how to reset root password

Ensure that all mysql processes are down.
Kill all one by one or use
killall mysqld
and/or
killall mysql
Then create a new file /home/usr_home/reset_root_pwd with the following content

UPDATE mysql.user SET Password=PASSWORD('YourNewRootPassword') WHERE User='root';
FLUSH PRIVILEGES;

Then login a console as mysql user and give the following command:
mysqld_safe --init-file=/home/usr_home/reset_root_pwd &

 
After stop the server and restart it.
Now You should be able to connect as root with the new password.

Bye...

Usefull links: 
- http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
- http://openskill.info/infobox.php?ID=1033