I accidentally deleted all users in MySQL including localhost. Now I can't even access my connections. How can I add localhost use to access my connections?
localhost is not a user, it's a special host, referring, well, to the local host. That means the host machine the software in question is running on.
So, when using a MySQL Client software like Navicat, localhost means that you want it to connect to a MySQL database that is running on the same machine as Navicat itself, instead of connecting over the network to a database running on some remote machine.
Now, regarding your question, if you deleted the user table (or its content) from the MySQL database running on your localhost, the only way I know of to bring the users back is restoring a backup of the database, if you have one.
You might be able to get access to the database again by recreating the user table using the mysql_install_db script as pointed out here, but this won't recover the previously existing users.
Related
Currently I have phpMyAdmin and MySQL installed on my server. I now want to provide access to phpMyAdmin to a friend of mine so he can setup his own databases and users, however I don't want him to be able to see or modify my databases.
Is this possible to do with a simple privilege account or do I require some kind of MySQL virtualization? I know cPanel installations provide this feature for web hosts, but I don't need or can afford cPanel at the moment.
You should look into MySQL Security Here specifically section 13.7.1.3 Grant statement. You could secure your DB from your friend logging in which will prevent him from seeing anything in that DB on PHPMyAdmin. Or you could create a DB for him to use and allow him access to that DB only.
You never mentioned if he will be on Localhost or will you need to open up MySQL for remote logins from other than Localhost which is the default behavior..
About 2-3 weeks ago I stopped using phpmyadmin and started using MySQL Workbench. Now, I can't connect to phpmyadmin. I tried connecting from two different computers and from the server. Tried connecting with at least 4 users and root. I am suspecting that this is Workbench's fault. During the time I used Workbench I made some changes to user privileges, but don't remember the specifics. I get "Wrong username/password".
Any thoughts ?
Looks like some of the comments have been deleted, but judging by what's left there was a suggestion for you to check your permissions for your user with hostname localhost, and it appears you did not understand that % is not the same as localhost. Many installations come with several root users, one for host localhost, one for host %, and sometimes a third for 127.0.0.1. This is normal and part of how MySQL handles permissions. TCP/IP connections match %, socket connections do not (they use localhost).
Another thing that's important to realize is that, when using phpMyAdmin, it doesn't matter what client machine you're using; what matters is what machine is the web server, since that's where the requests to MySQL come from. So you can easily get a bit confused if using a remote machine to connect to a web server running on the same machine via sockets to the MySQL server -- even though you're on a remote machine from the MySQL server, in this case it appears as a localhost connection to MySQL.
Anyway, very likely what happened was you were "cleaning up" extra users and removed one that had the opposite host value (either % or localhost); I'd simply recreate your user with the other host. That should clear it up for you.
I am working on a school project in which I have to upload data onto a database hosted on phpMyAdmin.
What's confusing me right now is that I see "localhost" at the top of the page and before I even query the database I see "Run SQL query/queries on server "localhost":"
Does this mean that I'm hosting a server on my computer and accessing the database through that? Because then I query for "SHOW VARIABLES WHERE Variable_name = 'hostname';" and it returns with hostname = webhost330. (It is hosted on webhost330.asu.edu).
I'm extremely confused about what this means. Thanks for any possible help.
I'm very new to databases so forgive me if I'm missing something simple here.
EDIT: To clarify: I'm not at school, I'm at my house. What kind of implications does this have? In other words, what's the difference between this and hosting a database locally?
When I host a database on my computer through the MySQL command line client, I can create database information and it's stored on my computer in files. Does this mean that it's initially stored on localhost and then that data is used to create files on my computer?
And then the equivalent of that for the webhost330 is that the localhost stores the database initially but then uploads it to the host at phpMyAdmin? That is the primary thing I'm confused about.
This exactly means what you assumed. When connected to localhost, you are connected to local MySQL server on same machine. Using webhost330.... you are connected to that remote MySQL server instance, if that is not the name of your own machine. Your own server can be webhost30.etcetc.
Edit
If your website is hosted here: webhost330.asu.edu then MySQL host either being webhost330.asu.edu or localhost both mean the same local MySQL server on your very machine.
Edit based on your update
If you are at home, then localhost means you are connected to a MySQL server that you have installed on your own computer. and webhost30.etc.etc means you are connected to the database you have at your school. Database do allow remote connectivity and if you are connected to school from home, that's a remote MySQL connection.
To remove your confusion, you should use only localhost in your code. localhost at home will mean the development server which is your home computer, and when you take the same code to webhost30.etc.etc then localhost for that server will mean its own MySQL installation. So localhost will work everywhere as long as you don't want your code to connect to a remote external MySQL database server.
Assuming you're at school, and assuming you're on your school network. Then yes, your machine is probably "webhost330.asu.edu". At the very least webhost330.asu.edu thinks "webhost330.asu.edu" is localhost.
To see what "localhost" refers to in terms of MySQL server, you have to look at the URL you are using to connect to the web server.
For example, if the URL is
http://localhost/phpmyadmin
and this instance of phpMyAdmin tells me that the MySQL server is on localhost, this means that the MySQL server is on my local workstation.
If the URL is http://example.com/phpmyadmin, then localhost will mean that the MySQL server is on the same machine (example.com).
I recently installed the XAMPP stack on a desktop and connected via a laptop on the local network. To my surprise, I was able to access phpmyadmin and delete update all mysql tables. Though I understand that I shouldn't use xampp for production (and I'm not), I would still like to learn how to manage these types of obvious security flaws. I know that I can block access to directories via .htacces (http://forum.directadmin.com/showthread.php?t=29089), but I would like something that is a little more comprehensive. How would you restrict running of mysql queries from anywhere except localhost? Is there a way without .htaccess? I thought this was partially the purpose of the root user.
MySQL defined users with domains. If you look at your user_privileges table in the information_schema database you will see that they all have domains. If all your users are defined strictly as localhost, there will be no remote access.
Also, you can edit my.cnf to turn off tcp access to the database, forcing all connections to be by socket. under [mysqld], include the line skip-networking. You will have to configure all your apps to use the socket connection, but I like the socket better anyway.
This will do nothing to protect your data from someone using phpMyAdmin, if phpMyAdmin is installed on the same machine as the database. The safest thing to do is get rid of that app. That's often not practical, however, as it's a useful tool, and so you need to configure phpMyAdmin to require that users authenticate themselves. That means NOT putting the password in the config file. You will need to think about how long sessions are before reauthentication, and things like that.
phpMyAdmin fills me with a rage hotter than a thousand suns whenever I try to configure it, but it is definitely possible to set things up so a password is required each time you connect to the database through phpMyAdmin. You can further limit the damage phpMyAdmin abusers can do my making sure it only connects as a user with limited privileges (for instance, only able to modify the database you're working on at the moment).
I have a domain name and my rails application.
Is there any way to connect with database without giving the IP address of that host name?
I need what changes are needed in my database.yml file.
The error you're seeing is almost certainly because you don't have a root#localhost user in your mysql database. It has nothing to do with the database configuration file.
You need to add the root#localhost user to your mysql database.
It goes without saying that you should not be using your root user in production and it is probably a good idea not to use it in dev either as it's level of privileges may be hiding some problems.
What errors are you seeing?
If you're asking how to connect to a database without using an IP address, that depends on whether or not your database running on the same machine that's hosting your rails app?
If you're database is on the same machine as your rails app, you can just use localhost as your database host name and that should work (assuming your database is running with the default configurations).