logging into sql - mysql

I am a student learning sql and working an assignment to set up a database in mySQL 5.5 community version. The command I am given does not work as detailed. Here is what I have done so far:
This is the command that I am told to use after setting up mySQL 5.5.
mysql –h localhost –u root -p
This brings back a long screen of help commands. I found out that instead I need to use:
mysql -u root -p. Then I get my password prompt that works. That starts sql. Next I was given these statements to create a user named user1.
USE mysql;
create user ‘user1’#’localhost’ identified by ‘user1’;
grant select, insert, update, delete, create, drop, references, execute on *.* to ‘user1’#’localhost’;
exit
I entered these line by line and they seem to work. No errors are returned. However when I try to start the user with the following commands:
Login as user1
mysql –h localhost –u user1 –p
password is user1
I get a long list of help commands when i exexute the mysql line.
What is incorrect with the commands I have executed and also why? I initially think it may be that these commands were written for an earlier version? I was initially told to reinstall mysql and did that with no errors. I get the same results as before reinstalling it. If I need to explain or add screenshots, I will be glad to do so.

http://dev.mysql.com/doc/refman/5.0/en/connecting.html
mysql -h localhost -u user1 -ppassword database_name_here
Your other option:
mysql -h localhost -u user1 -p database_name_here
But for the second one you will have to type the password.

Sorry for not answering you question specifically, but I recommend you to get an interface to mySQL which makes it all a bit easier. In my case I still use the terminal to perform some queries once in a while, but for user management and to get a better presentation I use phpMyAdmin which makes the whole process much more neat. Good luck!

Related

mysqldump Error 1045 Access denied despite correct passwords etc

This is a tricky one, I have the following output:
mysqldump: Got error: 1045: Access denied for user 'root'#'localhost' (using password: YES) when trying to connect
When attempting to export my database with mysqldump on Windows XP. The username is root, the password is correct and contains only alphanumeric characters. I have tried different cases, with/without quotes, specifying using -u and -p, specifying using --user= and --password= and other methods of specifying user/passwords etc, specifying the host (it's all local) and even specifying the database using --databases instead of just blank. The error is always the same when using a password and always the same except the "NO" message when without. I have tried many fixes found through searches with no success. One fix suggested inspecting mysql.conf, but the Windows build doesn't seem to have one. The credentials (and indeed commandline parameters) work perfectly with mysql.exe - this problem only seems to be affecting mysqldump.exe.
This worked for me
mysqldump -u root -p mydbscheme > mydbscheme_dump.sql
after issuing the command it asks for a password:
Enter password:
entering the password will make the dump file.
If you're able to connect to the database using mysql, but you get an error for mysqldump, then the problem may be that you lack privileges to lock the table.
Try the --single-transaction option in that case.
mysqldump -h database.example.com -u mydbuser -p mydatabase --single-transaction > /home/mylinuxuser/mydatabase.sql
Try to remove the space when using the -p-option. This works for my OSX and Linux mysqldump:
mysqldump -u user -ppassword ...
The access being denied is probably to the Windows file system not to the MySQL database; try redirecting the output file to a location where your account is allowed to create files.
You need to put backslashes in your password that contain shell metacharacters, such as !#'"`&;
Don't enter the password with command. Just enter,
mysqldump -u <username> -p <db_name> > <backup_file>.sql
Then you will get a prompt to enter password.
Access dined problem solved when I run command prompt in Administrator mode.
Go to Start-> All Programs -> Accessories right click on Command Prompt clickc on Run as.. Select The Following User select administrator username from select option enter password if any click OK button.
Example 1: For entire database backup in mysql using command prompt.
In Windows 7 and 8
C:\Program Files <x86>>\MySQL\MySQL Server 5.5\bin>mysqldump test -u root -p >testDB.sql
Enter Password: *********
In Windows xp
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump test -u root -p >testDB.sql
Enter Password: *********
It asks password for credentials enter password and click on Enter button.
Example 2: For specific table backup / dump in mysql using command prompt.
In Windows 7 and 8
C:\Program Files <x86>>\MySQL\MySQL Server 5.5\bin>mysqldump test -u root -p images>testDB_Images.sql
Enter Password: *********
In Windows xp
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqldump test -u root -p images>testDB_Images.sql
Enter Password: *********
Dumpt file will be created under folder
In windows xp
C:\Program Files\MySQL\MySQL Server 5.5\bin
In windows 7 and 8
C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin
Note: Check MySQL installation folder in Windows 7, 8 while run in command prompt. If MySQLWorkbench is 32 bit version it is installed in Program Files (x86) folder other wise Program Files folder.
Put The GRANT privileges:
GRANT ALL PRIVILEGES ON mydb.* TO 'username'#'%' IDENTIFIED BY 'password';
mysqldump -h hostname -u username -P port -B database --no-create-info -p > output.sql
I think you should specify the args
Doing without the -u and -p worked for me (when I was logged in as root):
mysqldump --opt mydbname > mydbname.sql
I was having the same issue, for 30min! I found that I was using _p instead of -p, the terminal font confused me!
Putting -p as the first option worked for me on Windows Server 2012R2 (in cmd.exe as Admin).
mysqldump.exe –p --user=root --databases DBname --result-file=C:\DBname.sql
I just ran into this after a fresh install of MySQL 5.6.16.
Oddly, it works without the password specified or flagged:
mysqldump -u root myschema mytable > dump.sql
mysqldump -u (user) -p(passwd) -h (host_or_IP) database_to_backup > backup_file.sql
example:
mysqldump -u god -pheaven -h 10.0.10.10 accounting > accounting_20141209.sql
this would create sql backup file for the accounting database on server 10.0.10.10. Sometimes your error is seen when localhost is not in config. Designating ip of server may help.
I had to remove the single ticks after the password flag:
--password=mypassword
and NOT
--password='mypassword'
Mysql replies with Access Denied with correct credentials when the mysql account has REQUIRE SSL on
The ssl_ca file (at a minimum) had to be provided in the connection paramiters.
Additional ssl parameters might be required and are documented here: http://dev.mysql.com/doc/refman/5.7/en/secure-connection-options.html
Also posted here https://stackoverflow.com/a/39626932/1695680
For MAMP PRO users (or anyone who's mysql is in a weird location) be prepared to specify the mysql full path from the boonies and also specify full path to your user local folder where you want to dump the file or you'll get the "permission denied error"..
Following worked for me after 3 hours of research:
/Applications/MAMP/Library/bin/mysqldump -u root -proot YOUR_DB > /Users/YOUR_USER/yourdump2.sql
In my case, I could access correctly with mysql.exe but not with mysqldump.exe.
The problem was the port for my connection was not the default one (3306) and I had to put the mysqldump port work with (-P3307)
mysqldump -u root -p -P3307 my_database > /path/backup_database
This is the solution that worked for me
mysqldump -h hostname.com -u username -p'password' database > dump.sql
In Past same problem occurred to me after I copied the mysqldump statement from a MS Word file.
But When typing the statement directly, everything worked fine.
In hex editor the "-" of the not working statement was represented by the unicode char e2 80 93 (http://www.fileformat.info/info/unicode/char/2013/index.htm)
In sort, type password directly and check the copy paste code as the uni-code (or other encoding) strings might cause an issue..
I had the same error for last 2 days. Tried bunch of things. Nothing worked.
But this did work:
Create another user. Grant it everything.
mysqldump -u new_user db_name > db_name.sql //no error
I discovered a running apache process acessing the MYSQL causing this error. So I suggest to ensure that all processes which might interact with the DB are shutdown beforehand.
I had the problem that there were views that had a bad "DEFINER", which is the user that defined the view. The DEFINER used in the view had been removed some time ago as being "root from some random workstation".
Check whether there might be a problem by running:
USE information_schema;
SELECT DEFINER, SECURITY_TYPE FROM views;
I modified the DEFINER (actually, set the DEFINER to root#localhost and the SQL SECURITY value to INVOKER so the view is executed with the permissions of the invoking user instead of the defining user, which actually makes more sense) using ALTER VIEW.
This is tricky as you have to construct the appropriate ALTER VIEW statement from information_schema.views, so check:
Modify DEFINER on many
views
MySQL error 1449: The user specified as a definer does not exist
For me it worked when I omitted the password.
So mysqldump -u user dbname > dump.sql
Tried most of the above with no joy.
Looking at my password, it had characters that might confuse a parser. I wrapped the password in quotes and the error was resolved.
-p"a:##$%^&+6>&FAEH"
Using 8.0
If you want to create a mysql data dump, you can use mysqldump command. Following command will create a sql file called xxx.sql at the same location from where this command is run. xxx.sql will have all the necessary sqls to replicate exactly same db schema in any other mysql database.
Command is : mysqldump -u root -ppassword --databases database Name you want to import > xxx.sql
Here root is the mysql root user and password is THIS root user's password.
EXAMPLE: If root user password is hello, database name to export is regdb and xxx.sql is the file where you want to export this regdb, command would be like:
mysqldump -u root -phello --databases regdb > xxx.sql
Note: xxx.sql is the file name where this db will get dumped.
This solution might be one of the last to try/least likely to be the culprit, but this was my problem...
My problem was that the directory I was trying to dump to needed admin privileges to write to and that's what was causing the mysqldump command to return "Access Denied".
I set the dump file path to my desktop dir and then it worked.
This was on Windows.
I had the same error. Only occurred after moving from my normal work PC to a PC at a different location.
I had to add my public IP ho address to Remote MySQL in my CPanel at my host site
I got the same error when I ran the command in a directory that I didn't have write access to.
Test your access by creating an empty file in the directory, and see if you get an error.
Here was my error
mysqldump -u root librenms -p > librenms.sql
-bash: librenms.sql: Permission denied
I changed to my home directory and then it worked.
cd ~
mysqldump -u root librenms -p > librenms.sql
Enter password:
Do the equivalent on windows, and it may just fix your problem!
ENSURE YOU TRY REMOVING AND TYPING THE DASH OVER to make sure that you are actually fighting with the right problem.
Be very careful that you actually have a "-". I apparently had some other character that looks very similar. I had a – instead of a -. I had copied the command from somewhere online don't remember where but the point is I spend a lot of time trying to figure it out when I just needed to replace that character.

Security of passwords in bash subcommands

I've heard that directly inputting your password on the command line is a bad idea, because anyone could see the "secret" in
mysql -u root -psecret
by browsing history.
I have a password for my MySQL database stored in a text file with limited read permissions, and was wondering if it is safe to access it in the following way:
mysql -u root -p$(cat ~/.mysql_pass)
Browsing history, I see the command printed, not the literal value. So it seems like it's working the way I want it to.
I'm sure there are better ways of handling passwords, I would just like to know whether or not this one is leaving my password completely out in the open.
You've suggested using the following:
mysql -u root -p$(cat ~/.mysql_pass)
However, the subcommand will be expanded before mysql is executed and so even if this isn't available in the command history, it's entirely possible for someone to view the process list just after invocation and see your password.
I think a better approach is to use a mysql client options file and have the mysql command read the password from the options file.
Just type mysql -u root -p and you'll get a prompt to enter your password and it won't be stored in the history.

mysqlcheck does not accept password

According to the mysqlcheck manual I can do the following:
mysqlcheck datatabase_name --auto-repair -ao -u="user" -p="password"
However it never accepts the password. It does not matter whether I use the shell or database login. When I leave the password, i can connect after it prompts me to put the password. I want to put it in a cron script so i need to be able to put the password inside the command.
Also am i right that this command will analyse, optimise and repair if needed?
Try using:
mysqlcheck datatabase_name --auto-repair -ao --user=user --password=password
or -uuser or -ppassword should also work.
Unfortunately I can't really provide any further insight into your queries on how effective mysqlcheck actually will be in what you want it to do. I suspect it won't do the things that will really improve DB performance though like adding well placed indexes and optimizing queries to only link where necessary.

Mac Mysql change password , No user table to run update query

I am able to login with root - "No password", But i can't change password. I checked many links , everybody saying to run update query on user table , but i even can't find user table in phpmyadmin.
Error I am getting is :
$ /usr/local/mysql/bin/mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
/usr/local/mysql/bin/mysqladmin: Can't turn off logging; error: 'Access denied; you need (at least one of) the SUPER privilege(s) for this operation'
Any help will be highly useful
PHP My ADMIN (Screenshot): http://awesomescreenshot.com/021cxa0fb
Error: http://i47.tinypic.com/1j1b0m.png
Additional screenshot: http://i48.tinypic.com/w9vbtl.png
Additional screenshot 2: http://i48.tinypic.com/4rymps.png
it seems to me, that you use phpmyadmin to look for the table. if so, you won't see all tables. you have to log in to mysql as root with the "mysql" command in the terminal:
$ mysql -u root
then you can run the "update user..."-command (you don't have to see the table containing the user informations)
another idea: when you use the -p in the command line, you are not allowed to write the password next to it (it will ask you later on). if you write something after -p it will think that this is the database name...
From the additional information you have posted in comments it appears that your MySQL root user no longer has root privileges on your system. After performing a quick search looking for mysql reset root privileges I found this blog posting that appears to give detailed instructions on how to restore root privileges to your root account.
BEWARE, I have not tried these steps and they are from 2009 and it's possible that MySQL may have changed internally from when these instructions were created. However, that being said, the comments on the posting are positive (of course, the comments could be fake).
My recommendation is to backup the directory (or directories) containing all of your MySQL data and then trying these steps EXACTLY as they are laid out.
Looking more closely at these instructions they appear valid to me. I noticed that they involve taking down the MySQL daemon, restarting MySQL with an option that turns off all table security and then executing updates to add rights back to the root user. I now recommend giving these steps a try.
To set the root's password:
/usr/bin/mysqladmin -root password 'new-password'
try to know if mysql daemon is up:
/usr/bin/mysqladmin -u root -p ping
if not alive try :
/etc/init.d/mysql start
& verify that mcrypt package is installed.
I solved the Problem , Thanks for all.I reinstalled the mysql server as per following guide , the problem was I updated password directly to the mysql.user table with update query , its wrong , since the password should be stored as encrypted in mysql.user table , if we updating it directly through query then it will be a string.
Excellant guide : http://blog.mclaughlinsoftware.com/2011/02/10/mac-os-x-mysql-install/
Thanks again for everybody :)

Avoiding MySQL1044 error

I am trying to learn PHP and MySQL and while I reached a chapter on MySQL I was asked to create a database using this command:
CREATE DATABASE publications;
After I typed it in the mysql console I got this error:
ERROR 1044(42000):Access denied for user ''#localhost' to database 'root'
I am already logged in to my administrator account so I think the privileges should't be a problem.I have installed with the XAMPP package.
How can this be solved?
It could be possible that you upgraded your version of EasyPHP or you did something to disable the root password. If that is the case, you should try reestablishing a password for root. Had the same problem and that's how I solved it.
Go to http://localhost/xampp/ and set the appropriate passwords (in Security tab). If you use mysql client program, make sure you call it with appropriate credentials: mysql -u <username> -p <password>. Username will mostly be root until you create some new accounts.
Then I suggest you use phpMyAdmin for experimenting with MySQL (it should be at http://localhost/phpmyadmin/ )
This is getting a little confused - let me try to answer this.
Mysqladmin is a command line client for administering your mysql database system - you normally don't need to run it once you have mysql working. The shell command line interface to the mysql server is mysql. (If you don't know how to run a shell command line, that's another problem. Also, if you're on Windows, say so, since that has its own challenges.) The arguments are:
mysql -u username -ppassword databasename
if you are running this command on the same server as mysql. Note the lack of space after the -p - that is important.
So, type the above line to invoke the command line interface to mysql. Then you can type your mysql commands. Things like show tables, desc tablename, etc., will work. That is they will work unless you have an authentication problem. But you will know you have an authentication problem because when you tried to run mysql as above, it will fail with some error, like "Access denied for user 'abc'#'localhost' (using password: YES)". This is a nice descriptive error message that points you exactly where the problem is.
Does that help?
You can go back to using xampp or anything else once you've made sure that you know the right parameters by checking with the command line. (Always check with the command line when strangeness happens - it's so much easier than trying to debug through other interfaces.)