I am trying to set up a mysql database on an aws ec2 instance (SUSE 32-bit with mysql pre-installed). However, I can't log in to mysql as root user:
mysql -u root
Access denied
without a password, so is there a way of getting one? I believe that root user is blocked and hence should login with ec2-user. However, when I do
mysql -u ec2-user
the user does not have the priviledges to create a database.
I'm a not very familiar with linux, so if I'm simply doing this completely wrong, then do say.
Any help would be greatly appreciated.
The fact that this server is on EC2 is irrelevant. SUSE and MySQL do not know this. Amazon cannot block anything, you have root access to the server. You recover/change the root password the same as any server, with mysqladmin, or by starting mysqld with --skip-grant-tables while you make the change.
mysql -u root -p
Then press enter.
I know, this isn't a direct answer to your question, but I would recommend using the AWS Relational Database Service. Amazon will host a MySQL database for you and take care of all the setup, maintenance, scaling, backup, etc.
http://aws.amazon.com/rds/
Related
I am quite stressed, I am afraid I have lost my databases. I wanted to access my database from another laptop, but I finally lost the connection to my databases, and when I found it again, my databases were gone.
I hope you will be able to help me or perhaps have some encouraging leads.
I wanted to access my database from another laptop, so I tried to change my hostname from "localhost" to my IP address on MySQL Workbench. This way I could not connect to MySQL, I tried to change my hostname back to "localhost" but I could not connect either.
Finally, since I'm on a Mac, I went to System Preferences > MySQL > Initialize Database, and changed to use legacy password encryption, as suggested in a tutorial. Then I can connect to the server, but there are none of my databases, just the original "syst" database.
Are you able to connect to your MySQL via command:
mysql -u username -ppassword (no interval after -p)
(bear in mind that you have to be in the bin dir of MySQL) for example using XAMPP in cmd, I can connect via the following commands:
cd C:\xampp\mysq\bin
mysql -u root -ppassword
If you are able to connect try to reach the database via command line like this:
mysql -u username -ppassword --execute="select * from databasename.table"
or just some other query just to check if the database is still there.
This should be done on the PC(or server) where the MYSQL is installed.
If this is working you can manage to fix the issues.
I am using "mysql -u root -p" command to start mysql but I am getting error as:
Access denied for user 'root'#localhost''
I always have to use sudo to to launch it. Other applications start normally. How do I get around it? I am doing jdbc connection (java). Mysql doesn't give access to database in java. I think requiring sudo command is the problem.
System:
Ubuntu 18.04 LTS dual booted with Windows 10.
I always have to use sudo to to launch it
No. You need to use sudo to get the client to authenticate against the server.
The reason for this is that recent versions of MySQL (and MariaDB, PerconaDB) use SO_PEERCRED to very that the username asserted in the connection string (root) is the same user as started the client (this makes use of a password somewhat redundant).
Since SO_PERRCRED only works on filesystem sockets (AF_UNIX) you may be able to bypass the constraint by connecting via a network socket, e.g.
mysql -h 127.0.0.1 -u root -p
But do be aware that MySQL typically has separate user records for connections via network (host != 'localhost') and filesystem (host='localhost') sockets.
But as per the question #Ciarambola flagged, 'root' is a special case and should not be used for routine access - you should create a new user.
Mysql doesn't give access to database in java
You should never use an admin account as the embedded credentials in an application. If you make that account with the same name as your user you won't need to use sudo when you connect to 'localhost'.
so I have two free gears on OpenShift.
One is a PHP with MySql 5.7 from:
https://github.com/icflorescu/openshift-cartridge-mysql
To which I can remote login from my PC without any problem by SSH tunnel.
Now on the second gear I wanted to create Spring Boot app that would connect to DB on the first gear. Using env | grep MYSQL on first gear I receive:
OPENSHIFT_MYSQL_DB_PORT=13306
OPENSHIFT_MYSQL_DB_HOST=127.10.104.130
So this + my logging data was put into Spring application.properties, after successfull build Spring crashed at data pool creation because it could not connect to database so I SSHed into second hear and tried accessing MySQL instance from first gear via:
mysql -u root -h 127.10.104.130 -P 13306 but I get error message:
Can not connect to MySQL Server on '127.10.104.130' (113)
After that I tried:
mysql -u root -h myAppName-domain.rhcloud.com -P 13306 which results in longer time of connection but ultimatelly failling with:
Can not connect to MySQL Server on 'myAppName-domain.rhcloud.com' (110)
And I can easly ping gear#1 from gear#2 so I am confused - do I need some extra sql config or firewall settings? I am also doing tail on mysql logs and nothing is showing up like connection is not even made.
If you are connecting on another gear you have to use the OPENSHIFT_MYSQL_DB_PROXY_PORT instead.
The easiest way I find to tell if its a database issue or a network issue is to simply try to telnet to the remote mysql host.
Ex - this should result in a connection timeout if you are on a different gear.
telnet 127.10.104.130 13306
But this should connect:
telnet <mysql app id>.domain.rhcloud.com <WHATEVER THE PROXY PORT IS>
I'm the author of the openshift-cartridge-mysql mentioned above.
It's been a while since I've published that cartridge, but if I remember correctly, the setup script is quite unassuming and there's nothing created by default, so you have to create your own users, databases and explicitly grant the appropriate privileges.
Connect from your PC either by ssh or by Workbench over ssh tunnel, create your user and database, then execute something like:
GRANT ... ; FLUSH PRIVILEGES;
You can learn more on MySQL's GRANT command in the official manual.
There's a line in the repo README exemplifying how you could grant remote access to root, which is not as unsafe as it looks because you can only access the DB gear from your main application gear.
But ideally you'd want to limit the access as much as possible (to a specific user coming from a specific host/IP, such as your main application gear). Something like this:
GRANT ALL ON appdb.* TO 'appuser'#'appgear';
Don't forget to FLUSH PRIVILEGES when you're done.
I hope this helps,
#icflorescu
I want to copy multiple MySQL databases that are hosted by a remote hosting company.
There are over 100 large databases so obviously I need a way to be able to download them all at the same time.
I have searched on-line for the correct and most secure way to do this. I realize that it must be done via command line on my computer.
I also realize that instruction like this is the right way to proceed:
mysqldump -u remoteusername -p remotepassword -h your.site.com databasename > dump.sql
mysql -u localusername -p localpassword databasename < dump.sql
my confusion is that I presumed that I need to connect to the external database via SSH?
If so, then I would really appreciate any advice on how to connect to the MySQL server via SSH.
I have searched this on-line but cannot seem to find any clear information or guidance on this.
The program "mysqldump" is a command-line program. You don't connect to a database; "mysqldump" connects to a database.
You login to a server (host). It might be the same server the dbms is running on, but it doesn't have to be. If you're running a web site on a shared host (a common scenario), the web site and the dbms usually run on two different servers. Your login might be through ssh, and it might not.
You login to a server that offers either
shell access (usually a bash shell), or
a graphical interface that lets you dump a MySQL database.
Exactly how to do any of these can vary a little from host to host. But an ssh connection usually looks something like this.
$ ssh username#hostname.com
Also, the MySQL username might or might not be the same as the login username.
I'm confused by the documentation. Do I still need to use a password to access MySQL in RDS?
Apparently you always need a password when accessing RDS
I am sorry, If I did not understand your question, but may be you wanted to ask... do I need to have a password to access my database in RDS using mySQL client tool?
If this is your question, then yes, you have to have a password for the schema. There is no password for "mysql" nor for "rds instance".
Basically you are connecting to the database that is residing in the RDS instance.
You can use the following command to connect to DB in RDS, you must have rds-end-point
mysql -h {rds-end-point} -u {user-id} -p {schema-name}
When you enter this command you will be asked for the password.
AWS documentation:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html