I am importing a sql file to database using command prompt.But getting an error of Access denied. Details:
user: staging
host : %
It works with the following details:
user : staginguser
host: localhost
Import command:
mysql -u staging -p dbname < filename.sql
Can anyone tell me how to import a file for user with host % ?
Thanks in advance
First, and only for clarity purposes, you may wish to put the dbname just after the MySQL command. Second, you may wish to check if the contents of the file has references to the source database name (something like .) and the old db name differs from the new. Third, check that user staging has access to the db and if yes, check that it has the required permissions to perform whatever is contained in the file.
After you have done all the above, post an update to your question with all the details.
By the way, if you are using % as the host, it means that the user must have access from any host. Does he/she?
Related
Non-coder here, please advise as newbie. I have a MySQL DB on my ISP's server that provides data for a web site. I want to set up a db on my localhost that I can use for local development. The DBs don't need to be linked, nor do they need to remain synchronized. I just need to start with a current copy of the ISP version.
I have used PHPMyAdmin on ISP to download what I think is a dump file. the file, [mydbname].sql shows the schema and all the data. I just can't figure out how to import it in MySQL Workbench on my local PC.
Using the MySQL Workbench Data Import tab, if I execute "Import from Dump Project Folder" where the .sql file is located, I get "There were no dump files in the selected folder."
If I select "Import from Self-Contained File" and select my ***.sql file, I get "ERROR 1142 (42000) at line 31: CREATE command denied to user 'root'#'localhost' for table 'account' Operation failed with exitcode 1"
I've attempted to give 'root'#'localhost' all privileges.
I'm guessing there's an issue with privileges. If there's another way to do this, I'd be thrilled to know it. Many thanks!
If what you have is a sql dump file then try this on the CLI:
mysql -h hostname -u user --password=password databasename < filename
Assuming of course that has the right privileges.
Non-coder here, please advise as newbie.
In that case, download heidisql : https://www.heidisql.com/
It also makes copying tables and database from server to server very easy.
Apart from that: there is most likely something wrong with your privileges. But you might have made that worse by trying to give privileges to root. The root user can already do everything. So maybe also have a look at this post : How can I restore the MySQL root user’s full privileges?
I use Ubuntu server 16.04 (xenial) with Mysql 14.14 Distrib 5.7.20 (x86_64) with EditLine wrapper.
I have a Wordpress site /var/www/html/${domain}/ which I've duplicated with cp into /var/www/html/test/ and changed wp-config.php accordingly.
I have exported a DB backup of ${domain} this way:
mysqldump -u root -p"${rps}" "${domain}" > /var/www/html/test.sql
This test.sql file weighs 22mbs, just like a regular sql backup of the site, so the operation seems to be successful.
I've also logged into the mysql console and created an authorized, all-privileged DB user and instance, for the test site:
CREATE user "test"#"localhost" IDENTIFIED BY "${sps}";
CREATE database test;
GRANT ALL PRIVILEGES ON test.* TO test#localhost;
Note: rps and sps stand for "(mysql) root password" and "(mysql) site password". Echoing both show correct values.
I then exited back to the Ubuntu console.
So far so good, but here's the problem:
While in /var/www/html/ I tried to import my test.sql file into it's corresponding DB instance:
mysql -u test -p"${sps}" < test.sql
And yet, my import operation fails.
I also tried this import syntax:
mysql -u test -p"${sps}" test < test.sql
Both import operations failed with the exact same error:
ERROR 1045 (28000): Access denied for user 'test'#'localhost' (using
password: YES)
My question
Why would I be denied access when I seem to use the correct password?
I emphasis that I've double checked and ensured that ${sps} holds the correct password by echo ${sps}.
Update_1
Even though this session includes the main parts of the code, you can view the entire code here.
Update_2 --- milestone
It seems that the problem is due to the variable not being expanded when the user is being created:
CREATE user "test"#"localhost" IDENTIFIED BY "${sps}";
I've confirmed this when manually creating a user with a password. Passwords fromo variables just won't count.
The reason it happens is because the variable ${sps} didn't get expanded inside the Mysql shell; Mysql shell isn't bash and doesn't include this behavior of variable expansion (in this case, of the type variable substitution).
See more data and a way to cope with this here.
I asked this question 1 hour ago:
How can I transfer my data from one database(000webhosting.com) to another(shatellhost.com)? note: I use 000webhosting.com free hosting service and I can't create full backup. my data is phpfox social networking.
No one answered so I did this:
I transfered (download) whole data in public-html in 000webhosting.com to my computer and then uploded whole that to public-html of my new host in shotellhost.com, then when i try to open my site: www.ibiology.ir this appears:
Cannot connect to the database:
Can't connect to MySQL server on 'mysql5.000webhost.com' (4)
How can i change MySQL address to new MySQL?
Do a mysqldump and then import the SQL into your new database.
backup: # mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
restore:# mysql -u root -p[root_password] [database_name] < dumpfilename.sql
This error appears to be due to the configuration file of your PHP code, the connection information did not changed properly when you change the host.
First thing to do is make sure that you have change your database. Because of the security reason, most hosting service does not allow connecting to there mysql server from another location. There for, you connect to the mysql5.000webhost.com from another server.
Second, review the code to find out which file containing the database connection information, which usually includes: database hostname, database username, database password, database name. If you use an PHP framework, check the documentation.
In general, this is what I usually do when moving a site to another host:
Open the PHPMyAdmin in my old host control panel
Export the full data of the current database. I usually check DROP TABLE/DROP VIEW option.
Save the exported sql file to my local drive
Open the control panel of my new host
Finding the MySQL configuration option. You may find the MySQL host name here, usualy is localhost (yes, 000webhost is a special case when not use this default host name).
Create the database and the user if necessary.
Write the database hostname, database username, database password, database name information properly into your php configuration file of your source code.
Open the PHPMyAdmin in the control panel of the new host, go to my database (just created) and import the previous sql file.
If everything works well, your code may work.
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 :)
I don't know much about MySQL at all. But I am trying to reverse engineer a MySQL database using Visio. I know what steps I should take to do this, but I can't get my database to show in the 'Databases' section (as below):
How do I create the MySQL database using the .SQL file and get it to show up in this list? I have tried this code:
mysql -u username -p password database_name < filename.sql
using my own credentials of course. But that doesn't seem to work. In what folder should the .SQL file be placed if this statement is to work?
1) Create a file "filename.sql"
2) Create a database in your DB in which you want to import this file.
3) From command-prompt/terminal, move to the directory where you have created a "filename.sql".
4) Run the command: mysql -u username -p password database_name < filename.sql. (You can also give the proper path of your file and run this command from anywhere). It might be the case that you don't have a password set for MySQL. If so, mysql -u username database_name < filename.sql will also work.
In your case if you have created a database with name ojs and also created a file with name ojs.sql in C: drive then run the following command:
Edit: Put the path inside quotes.
mysql -u username -p password ojs < "C:\ojs.sql"
There is another way of importing tables in mysql. You can do it this way as well:
1) Connect your database
2) Type command "use ojs;"
3) Type command "source C:/ojs.sql"
Most MySQL SQL files that create databases create the database 'on-the-fly', so you typically needn't do anything except:
log-in
mysql -u [username] -p[password]
(Note: make sure you do NOT include a space (' ') character between the -p and the [password].
MySQL will think that [password] is the name of the database you want to connect to.
The 'general' log-in (above) does not assume you want to connect to any particular schema.)
source the file (do not use quotes around filename)
mysql> source [database_creation_file].sql
you can simply do it using mysql workbench
1> create a new query tab
2> CREATE DATABASE database_name;
3> USE database_name;
4> open the filename.sql file and execute it ctrl + shift + enter
5> all the tables in the filename.sql are created
To create a MySQL database using a SQL file, you can follow these steps:
Log in to your MySQL server using the mysql command-line tool and the appropriate credentials.
Use the CREATE DATABASE command to create a new database with the desired name:
CREATE DATABASE database_name;
Use the USE command to switch to the newly created database:
USE database_name;
Use the SOURCE command to import the SQL file into the database:
SOURCE path/to/sql/file;
The database will now be created and populated with the data from the SQL file. You can verify this by running some SQL queries against the database.
It's important to note that this process assumes that the SQL file contains valid SQL statements compatible with the version of MySQL you are using. If the SQL file contains any errors or unsupported statements, they will be displayed in the mysql command-line tool, and the import process will be interrupted.