Trying to set MySQL root password results in error - mysql

I'm still very new to MySQL and Debian, but have been reading a lot during the last days.
I have a root account to a virtual machine that I want to use for Wordpress. One thing I read was that I should password protect MySQL because by default root user doesn't need a password for it.
I read someone doing it like this:
mysql> mysqladmin -u root password mypassword;
But that gives me the following error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqladmin -u root password mypassword' at line 1

You are running the command from within mysql, but the command is actually meant to be run directly from the terminal.
mysqladmin -u root password mypassword
If you are already in mysql within terminal, type exit then enter your mysqladmin command.

Related

Basic MySQL syntax error when trying to connect to server [duplicate]

I am connecting to database mysql using command prompt using below command
mysql -h localhost -u test -ptest test;
But i am getting following error:-
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
-h localhost -u test -ptest test' at line 1
I have done a lot of googling but could not find the reason behind this problem. Any help?
It seems you are executing the statement at mysql command line console but not at system shell prompt.
The statement
mysql -h localhost -u test -ptest test;
is for system shell prompt.
And while running at command prompt, you don't need to terminate the command by a semi colon.
And for suppressing use of password at command line,
change
-ptest
to
-p
It then prompts you to input your password.
You need to run that command (which starts the mysql shell) from the command prompt.
You are trying to run it inside the mysql shell.
First make sure your command line doesnt show
mysql>
prefix. if it shows you are already in the mysql console.
you have to type the command outside the mysql console.
mysql -h localhost -u test -ptest
That will fix you issue.
Refer Mysql documentation for more information
http://dev.mysql.com/doc/refman/5.0/en/connecting.html
Thanks.
mysql -u root -p -h localhost
then command would ask for password, input it and you can logged into mysql server

mysql error ubuntu Unknown database

I am a beginner in linux, I have installed mysql on linux and added 'khalil' as password to root user
when I want to connect :
mysql -u root -p khalil
I need to retype password, when I retype it, I have this error:
ERROR 1049 (42000) : unknown Database 'khalil'
I have the same error when I want to connect to phpmyadmin
1045 Cannot log in to the MySQL server
The command is
mysql -u root -pkhalil
Mind the missing space after -p
However, using a password on the command line can be dangerous (like mysql will warn you too), so consider using
mysql -u root -p
and type the password once you are prompted to.

How can I connect to MySQL server remotely using MySQL command line client (In Windows)? keep getting error 1064 (4200)

I'm using this method below to connect to my remote MySQL database but I keep getting this error message back:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-u admin -p demo123-h testaurora-cluster-1.cluster-tjiy9ao2kavg.us-west-2.' at line 1
Method:
mysql -u USERNAME -p PASSWORD -h HOSTNAMEORIP DATABASENAME
The options above means:
-u: username
-p: password (**no space after**)
-h: host
last one is name of the database that you wanted to connect.
Look into the the link, it's detailed there!
Code entered in MySQL command line client:
mysql -u admin -p demo123-h testaurora-cluster-1.cluster-tjiy9ao2kavg.us-west-2 TestTable
I would highly appreciate it if you can let me know what I am missing here..

How do i connect to the Live database(Mysql) using Mysql command prompt?

I have tried the following command syntax to connect with live
database...
-u Username -pPassword -h HostName Database Name
But there is an error
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MYSQL server version for the right
syntax to use near ' -u Username -pPassword -h HostName Database Name'
The command you're describing is for connecting to the database in command line. If you need to connect to a database inside a PHP script, you must use:
mysqli_connect aka mysqli::__construct
PDO::__construct
I'm not recommending it but if you're stuck with legacy code, mysql_connect also does the same for the deprecated mysql_* extension.
Try this... This might help you
connect to mysql database using command line and php
You must be using this command already on mysql shell prompt or on phpmyadmin like sql frontend. You must not use this command on mysql-shell as you are already loggin into mysql. Try this command on bash shell on linux or dos prompt on windows.
mysql -u Username -pPassword -h HostName DatabaseName
One more thing, If you are using windows (like wamp/xampp). You may need to pass full mysql path like
c:\wamp\bin\mysql\mysql -u Username -pPassword -h HostName DatabaseName

import a dump file mysql ubuntu

I installed mysql server on my machine running ubuntu then after installation I did the following:
mysql -u root -p to get mysql prompt
2.create database prediction ;
create user adam;
set password for adam = password("12211");
grant all privileges on prediction.* to adam identified by '12211';
use prediction;
-u adam -p prediction
I get the error :
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-u khalil -p prediction
Your error message doesn't correspond to your #6 entry (adam v.s. khalil). In any case, you cannot simply enter -u whatever into the mysql command line. Those are command line options, not sql commands/queries. You'd need to EXIT mysql first, then re-enter
$ mysql -u adam -p prediction
at the shell prompt