mysql restoring data on localmachine where the password is empty - mysql

I use a ruby program to download data from staging server and to populate that data to my local mysql server where the userid is root and password is empty.
cmd = "mysql -u #{user} -p'#{password}' my_db < out.sql"
Since password is empty, I get prompted for password. I just have to hit enter. I would like to avoid that. What's the fix?

Omit the -p option.

Related

Which username and password does mysqldump expect?

I'm trying to make a copy of my website's database, so that I can download it and import it into wamp for local testing.
Here is what I'm entering in Putty:
mysqldump -u my_database_username -p dataname_db.sql --single-transaction --quick --lock-tables=false > dataname_db_local-$(date +%F).sql && gzip dataname_db_local.sql
No matter what combo of user and pass I use, I get this error
Got error: 1044: "Access denied for user to database when selecting the database
It wants the MySQL user that has full privileges to that database, right? ie the same credentials as what I use to connect to the database in a new MySQLi() command in php, right?
I read that sometimes passwords with special characters aren't allowed, so I made a new user, full priveleges, for that database with a plain alphanumeric pass, but it's still not accepted.
I then thought maybe it wants the same username and pass as what I use to connect to my server via Putty, but that didn't work. Neither did -u root with the server password.
Can someone please clarify exactly which username it wants?
Thank you
Yes, you are right, mysqldump requires exactly the same username and password as what you use to connect to the database in a new MySQLi() command in php.
Make sure your account has Lock_Table privilege.
If it still didn't work, try to pass the –-single-transaction option to mysqldump:
mysqldump --single-transaction -u db_username -p DBNAME > backup.sql
Notice that there is a syntax problem, you should select your DB at last of mysqldump statement:
mysqldump [options] db_name [tbl_name ...] > filename.sql
Reference: [1] , [2]

How to re-setup Database configurations in Icinga2 server?

I am using ubuntu 16.04 and mysql DB ,i configured DB for icinga2 server and i created separate user in database.
somedays back i deleted that user from db now i am not able access icingaweb2 UI,
Getting below error while trying to access to the link.
All configured authentication methods failed. Please check the system log or Icinga Web 2 log for more information.
I followed the below link to install icinga2 server
Please Help.
I resolved the issue by re-creatinging a setup token in in the Icinga Web 2 by using bellow command
sudo icingacli setup token create
i got some error's while creating setup token and it is easily resolved by using [1]: https://monitoring-portal.org/index.php?thread/40111-icingacli-does-not-work/
If you still have access to the MySQL DB you should do a backup first of your icinga2 DB.
mysqldump -u [username] -p [password] [databasename] > [backupfile.sql]
Then purge MySQL or follow the guide on how to reset your root password
After you have access to the DB again if you purged MySQL use this to bring your data back in.
mysqldump -u [username] -p [password] [databasename] < [backupfile.sql]
If you only lost your password to IcingaWeb2 or now have access to MySQL then create a MD5 based BSD password algorithm:
openssl passwd -1 "password"
Note: The switch to openssl passwd is the number one (-1) for using the MD5 based BSD password algorithm.
Insert the user into the database using the generated password hash:
````
INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('icingaadmin', 1, 'hash from openssl');
Source

Login to the WAMP mysql console

After I went to phpMyAdmin to create new user.
Username: ken
Hostname: localhost
Password: 123456
Checked Global Privilege
When I start the MySQL console, it said that I need to enter the password. I pressed [ENTER] and it seem I have login to root. I haven't create password for root yet, Do I have to create a password for root? (I know it kinda dumb question, but I just want be crystal clear and simple answer)
Also, If I wanted to login to my newly created user, how do I do it?
I tried:
mysql> mysql -h localhost -u ken -p
->exit
Nothing happened.
The MySQL Console menu item in WAMPServer is setup to use the root account.
As the root account comes out of the box with no password set, then the correct thing to do is to just hit enter when the mysql processor asks for a password.
If you set a password on the MYSQL root account then when the MYSQL Console asks for a password you can use the newly created password.
If you want to login to MYSQL using a different user account, then it is simpler to use a command window and CD into the mysql folder and run the mysql.exe processor from there like
> cd \wamp\bin\mysql\mysql{version}\mysql
mysql -uken -p
I personally use a little batch file, that I store in a folder that is already on the windows PATH, never add a wamp folder to the windows PATH as this will mess you up when/if you ever install more than one version of MYSQL in your WAMPServer!
mysqlpath.bat
echo off
if %1.==. GOTO ERROR
PATH=%PATH%;c:\wamp\bin\mysql\mysql%1\bin
echo
echo -----------------------------------------------
mysql -V
echo -----------------------------------------------
echo
GOTO EndPHP
:ERROR
echo -----------------------------------------------
echo Parameter 1 should be something like 5.4.13 to use mysql5.4.13
echo -----------------------------------------------
:EndPHP
Then you run it like
>mysqlpath 5.7.10
and it sets that path up just for the duration of the command windows life.
First of all you have to logout of your current and then login with your new user:
For exiting just type:
> exit;
Then login with your new user:
$ mysql -u <username> -p
Keep in mind that:
By default mysql logic try with host localhost, otherwise if your server it's in another host just add the flag -h <your-hostname> at the end of your Shell request.
By default also, mysql try with port 3306, otherwise if your mysql's server port it's in another port just add --port=3333 at the end of your Shell request.
Keep in mind that if you aren't enable to run console interface of mysql you can use a Environment PATH for executing mysql otherwise you must edit your comand... changing mysql by the path to the wamp mysql bin location.
Let's supose you have mysql in this location: C:\wamp\bin\mysql\mysql5.7.19\bin, then, your comand will be:
D:\wamp2\bin\mysql\mysql5.7.19\bin\mysql.exe -u <username> -p
And that's it. If you have any issue please let me know, I will gladly help.
Resources:
How to manage MySQL databases and users from the command line

Restoring mysql backup without users

I have a confusion actually. While restoring the mysql backups, we generally use this command.
mysql -u username -p password databasename < backup.sql.
I just tried "mysql databasename < backup.sql" and that seemed to work too. So my confusion is, why do we add username / pass and what are the benefits / disadvantages of using / not using it?
If your MySQL doesn't have blank user and blank password then you couldn't able to import the database.
By default- Mysql installation comes with blank username and password in that case you can restore database without username and password only.
But if you have secure installation of mysql, means removed bkank user than you need to pass privileged username and password to restore the database.
While using mysql command for importing database, you can use either full command or skip some of the parameters.
You can also use :
mysql -u username -p password < backup.sql
This will create the database (if your dump have create database command) and import the tables into that.

Using Putty to import a sql file into the database

I want to import an .sql file into a database on the server through command line.
I understand that I should use the follow line:
mysql -u username -p database_name < textfilewithsqlstatments.sql
the sql file is currently in my local folder, shall I upload it to the server first? how should I specify the directory for this file?
Thanks
The line
mysql -u username -p database_name < textfilewithsqlstatments.sql
Assumes that the file is in the same directory that you are running the command from.
You should upload the file to the server and specify the path as
mysql -u username -p database_name < /path/to/file/on/server/textfilewithsqlstatments.sql
U can use the putty utility PLINK.EXE
Preferred configure the session with a key, to not need to put the password in all the connections, so simple use:
plink mysql -u username -p database_name <
textfilewithsqlstatments.sql
Considering that the file
textfilewithsqlstatments.sql
is in your /home/user.
More information about PLINK: http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html
It works fine!
STEP1:
enter your Hostname or I.P address and use port 22 # putty.
If you are entering your hostname, leave out the http://www and simply enter yourdomain.com.
STEP2:
You can then enter your cPanel username and click enter
STEP3:
Then enter your cPanel password and click enter.
STEP4:
finally step is to enter the command line below
mysql -u database_user_name -p database_db_name < /home/alphabettechnologies/public_html/alphabet_webz.sql
and click enter. (make sure to replace the path with the correct address to your database. The filename for your SQL database file, You’ll also need to replace with your new database username and password.
mysql -u database_user_name -p database_db_name < /home/alphabet/public_html/db-backup.sql
STEP5: enter the db user password
Thats All, will be db imported