I am continuously receiving this error.
I am using mySQL Workbench and from what I am finding is that root's schema privileges are null. There are no privileges at all.
I am having troubles across platforms that my server is used for and this has been all of a sudden issue.
root#127.0.0.1 apparently has a lot of access but I am logged in as that, but it just assigns to localhost anyways - localhost has no privileges.
I have done a few things like FLUSH HOSTS, FLUSH PRIVILEGES, etc
but have found no success from that or the internet.
How can I get root its access back? I find this frustrating because when I look around people expect you to "have access" but I don't have access so I can't go into command line or anything and GRANT myself anything.
When running SHOW GRANTS FOR root this is what I get in return:
Error Code: 1141. There is no such grant defined for user 'root' on
host '%'
If you have that same problem in MySql 5.7.+ :
Access denied for user 'root'#'localhost'
it's because MySql 5.7 by default allow to connect with socket, which means you just connect with sudo mysql. If you run sql :
SELECT user,authentication_string,plugin,host FROM mysql.user;
then you will see it :
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | | auth_socket | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *497C3D7B50479A812B89CD12EC3EDA6C0CB686F0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)
To allow connection with root and password, then update the values in the table with command :
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'Current-Root-Password';
FLUSH PRIVILEGES;
Then run the select command again and you'll see it has changed :
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | *2F2377C1BC54BE827DC8A4EE051CBD57490FB8C6 | mysql_native_password | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *497C3D7B50479A812B89CD12EC3EDA6C0CB686F0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)
And that's it. You can run this process after running and completing the sudo mysql_secure_installation command.
For mariadb, use
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('manager');
to set password.
More at https://mariadb.com/kb/en/set-password/
Use the instructions for resetting the root password - but instead of resetting the root password, we'll going to forcefully INSERT a record into the mysql.user table
In the init file, use this instead
INSERT INTO mysql.user (Host, User, Password) VALUES ('%', 'root', password('YOURPASSWORD'));
GRANT ALL ON *.* TO 'root'#'%' WITH GRANT OPTION;
It didn't like my user privilege so I SUDO it.
(in bash << sudo set user and password)
(this gives username of root and sets the password to nothing)
(On Mac)
sudo mysql -uroot -p
Try the following commands
~$ sudo /etc/init.d/mysql stop
~$ sudo mysqld_safe --skip-grant-tables &
~$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> use mysql;
mysql> update user set password=PASSWORD("root") where User='root';
mysql> flush privileges;
mysql> quit
~$ sudo /etc/init.d/mysql stop
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe --skip-grant-tables
~$ sudo /etc/init.d/mysql start
~$ mysql -u root -p
* MySQL Community Server 5.6.35 is started
~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
for the people who are facing below error in mysql 5.7+ version -
Access denied for user 'root'#'localhost' (using password: YES)
Open new terminal
sudo /etc/init.d/mysql stop
...
MySQL Community Server 5.7.8-rc is stopped
sudo mysqld_safe --skip-grant-tables &
this will skipp all grant level privileges and start the mysql in safe mode
Sometimes the process got stucked just because of
grep: write error: Broken pipe
180102 11:32:28 mysqld_safe Logging to '/var/log/mysql/error.log'.
Simply press Ctrl+Z or Ctrl+C to interrupt and exit process
mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.8-rc MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string=password('password') where user='root';
Query OK, 4 rows affected, 1 warning (0.03 sec)
Rows matched: 4 Changed: 4 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
sudo /etc/init.d/mysql stop
..180102 11:37:12 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
.
* MySQL Community Server 5.7.8-rc is stopped
arif#ubuntu:~$ sudo /etc/init.d/mysql start
..
* MySQL Community Server 5.7.8-rc is started
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.8-rc MySQL Community Server (GPL)
after mysql 5.7+ version the column password replaced by name authentication_string from the mysql.user table.
hope these steps will help anyone, thanks.
I was using ubuntu 18 and simply installed MySQL (password:root) with the following commands.
sudo apt install mysql-server
sudo mysql_secure_installation
When I tried to log in with the normal ubuntu user it was throwing me this issue.
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
But I was able to login to MySQL via the super user. Using the following commands I was able to log in via a normal user.
sudo mysql
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
exit;
Then you should be able to login to Mysql with the normal account.
If you are getting this error in Workbench but you are able to log in from terminal then follow this steps.
First simply log in with your current password:
sudo mysql -u root -p
Then change your password because having low strength password gives error sometimes.
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new-strong-password';
FLUSH PRIVILEGES;
Then simply exit and again login with your new password:
quit
sudo mysql -u root -p
Once you successfully logged in type the command:
use mysql;
It should show a message like 'Database changed' then type:
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
After that type:
UPDATE mysql.user set authentication_string=PASSWORD('new-strong-password') where user='root';
Then type:
FLUSH PRIVILEGES;
Then simply exit:
quit
Now try to log in with your new password in your WORKBENCH. Hope it will work. Thank you.
A simple way to reset root password on Linux systems :
sudo dpkg-reconfigure mysql-server-5.5
Checkout some other reasons for Access denied :
https://dev.mysql.com/doc/refman/5.7/en/problems-connecting.html
I faced this problem while installing Testlink on Ubuntu server, I followed these steps
mysql -u root
use mysql;
update user set password=PASSWORD("root") where User='root';
flush privileges;
quit
Now stop the instance and start again i.e
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
For my case, I found this error after fresh installation of mysql on Mac OS Big Sur.
What i did to fix it was:
I click on the apple logo, go to system preferences and then click on mysql.
There's an initialize database button on the opened settings window, I click on that, and then when I try to access again, it's solved.
in mysql 5.7 the password field has been replaced with authentication_string so you would do something like this instead
update user set authentication_string=PASSWORD("root") where User='root';
See this link MySQL user DB does not have password columns - Installing MySQL on OSX
Well the easiest way to reset root password is:
restart mysqld --skip-grant-tables option. This enables anyone to
connect without a password and with all privileges. Because this is
insecure, you might want to use --skip-grant-tables in conjunction
with --skip-networking to prevent remote clients from connecting.
Connect to the mysqld server with this command:
shell> mysql Issue the following statements in the mysql client.
Replace the password with the password that you want to use.
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root'; mysql> FLUSH PRIVILEGES;
Stop the server, then restart it normally (without the --skip-grant-tables and --skip-networking options).
Source Mysql documentation and personal experience:
http://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html
I resolved the same issue by running Workbench as administrator.
...I guess it's because of restrictions on company computers, in my case...
MySQL default password for root is assigned depending on the way you have installed MySQL.
If you have installed it from MySQL Yum repository, MySQL SUSE repository, or RPM packages directly downloaded from Oracle, you can obtain the password using following command:
sudo grep 'temporary password' /var/log/mysqld.log
In my case:
I set plugin authentication to "" (empty) and I can't run mysql server:
SOLUTION:
nano /etc/mysql/my.cnf
edit:
[mysqld]
skip-grant-tables
service mysql restart
mysql -u root
use mysql
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root'
flush privileges
Try out the following steps to overcome this issue:
Open terminal / command prompt and navigate to the bin folder of the MySQL installation folder. Then run the command mysqld --console.
If you can see that line 171010 14:58:22 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled, after executing the above command from the command prompt.
Then you need to check that the mysqld is either blocked by the Windows Firewall or another program.
If it's blocked by Windows Firewall then need to unblock from it and save settings.
To unblock the mysqld or mysql application, follow the below steps:
Go to command prompt and type wf.msc to open the firewall settings.
Click on Allow an app or feature through Windows Firewall.
Check the mysqld or mysqld instances are available in the list and check the checkbox for the domain, public and private and save the settings.
Return to the bin folder and try the command from step 1 again.
It should work fine and not show any errors.
It should be possible to run the MySQL console without any problems now!
I resolved the same issue using next sql and restarting MySQL server:
update mysql.user set Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y',Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y',Create_user_priv='Y',Event_priv='Y',Trigger_priv='Y',Create_tablespace_priv='Y'
where user='root';
I worked on Access Denied for User 'root'#'localhost' (using password: YES) for several hours, I have found following solution,
The answer to this problem was that in the my.cnf located within
/etc/mysql/my.cnf
the line was either
bind-address = 127.0.0.1
(or)
bind-address = localhost
(or)
bind-address = 0.0.0.0
I should prefer that 127.0.0.1
I should also prefer 0.0.0.0, it is more flexible
because which will allow all connections
I don't think you have to escape the --init-file parameter:
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe" --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.6\\my.ini" --init-file=C:\\mysql-init.txt
Should be:
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe" --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.6\\my.ini" --init-file=C:\mysql-init.txt
for the above problem ur password in the system should matches with the password u have passed in the program because when u run the program it checks system's password as u have given root as a user so gives u an error and at the same time the record is not deleted from the database.
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
class Delete
{
public static void main(String []k)
{
String url="jdbc:mysql://localhost:3306/student";
String user="root";
String pass="jacob234";
try
{
Connection myConnection=DriverManager.getConnection(url,user,pass);
Statement myStatement=myConnection.createStatement();
String deleteQuery="delete from students where id=2";
myStatement.executeUpdate(deleteQuery);
System.out.println("delete completed");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Keep ur system password as jacob234 and then run the code.
With me was the same problem, but it was caused, because i was using the mysql server on 32 (bit) and the workbench was running on 64(bit) version. the server and the workbench need to has the same version.
xpress
I was facing the same problem when I'm trying to connecting Mysql database using the Laravel application.
I would like to recommend please check the password for the user. MySQL password should not have special characters like #, &, etc...
cause might be missing mysqld file in /var/run/mysqld
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables
sudo service mysql start
if file does not exits then create file
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
check now you are able to login mysql -uroot -p123
otherwise do
sudo mysql -u root
use mysql;
show tables;
describe user;
update user set authentication_string=password('1111') where user='root';
FLUSH PRIVILEGES;
exit;
mysql -uroot -p123
link - mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists
For windows:-
If the instance configuration fails with similar issue and if you cannot log in to the root account.
Steps I followed to fix the issue:-
Stop MySql service if running.
Uninstall MySql using 'remove' option from the installation wizard.
If MySql service is not removed from services,
sc delete <MYSQL_SERVICE_NAME>
Delete all data containing in the MySql folder ('Program files', 'Program data' or the custom installation directory you have given).
Remove MySql path from the environmental variable.
Disable windows firewall.
Reinstall and config root account with new password.
the only thing that worked was sudo mysql followed by adding skip-grant-tables in [mysqld] section of /etc/my.cnf file - Ubuntu Mysql 5.5
alter user 'root'#'localhost' identified with mysql_native_password by '$your_password$';
it worked for me.
note: use strong password
for example
alter user 'root'#'localhost' identified with mysql_native_password by 'root';
Same issue occurred with me also, turned out my db username was wrong
I am trying to get this sample working without success
I installed and initialized the client:
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update \
&& sudo apt-get -y install google-cloud-sdk \
&& sudo apt-get -y install google-cloud-sdk-app-engine-java \
&& sudo apt-get -y install google-cloud-sdk-app-engine-python \
gcloud init
Then I authenticated successfully:
gcloud auth activate-service-account 13672300789-compute#developer.gserviceaccount.com --key-file=DockerStorage-e7def0adcafb.json
Then I tried the quick start sample:
Storage storage = StorageOptions.getDefaultInstance().getService();
String bucketName = "my-first-bucket"; // "my-new-bucket";
Bucket bucket = storage.create(BucketInfo.of(bucketName));
System.out.printf("Bucket %s created.%n", bucket.getName());
BOOM unauthorized
Exception in thread "main" com.google.cloud.storage.StorageException: 401 Unauthorized
What did I miss?
At first, You have to a generate a Service account credential.
Generating a service account credential
To generate a private key in JSON or PKCS12 format:
Open the list of credentials in the Google Cloud Platform Console.
Google Cloud Platform Console
Click Create credentials.
Select Service account key.
A Create service account key window opens.
Click the drop-down box below Service account, then click New service account.
Enter a name for the service account in Name.
Use the default Service account ID or generate a different one.
Select the Key type: JSON or P12.
Click Create.
Then simply use the credential json file in you code.
StorageOptions storageOptions = StorageOptions.newBuilder()
.setProjectId("YOUR_PROJECT_ID")
.setCredentials(GoogleCredentials.fromStream(new
FileInputStream("path/YOUR_SERVICE_ACCOUNT_CRENDENTIAL.json"))).build();
Storage storage = storageOptions.getService();
Hrm...good question. Theoretically this should work If you don't otherwise specify auth, that library will first attempt to use the credentials file specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable, and if that's not set, it should go looking for your gcloud credentials.
I'm guessing that it can't find your gcloud credentials for some reason. By default, they'll be in the ".config/gcloud" directory under your home directory, but that can be overridden. Maybe check to see if there're some files there?
One thing worth trying is simply copying a service account's JSON file to that machine and specifying the path to it with the GOOGLE_APPLICATION_CREDENTIALS environment variable. That shouldn't be necessary, but if that fails as well, something more interesting is going on.
I've spent 2+ days trying to get this to work and hope somebody might be able to point me in the right direction...
I am trying to run Tomcat 8 on Windows Server 2012 R2 as a service as a specific username. Due to the complexity of my application I am directly running tomcat8.exe //IS/... instead of using the service.bat script.
When the service runs I get these errors in the commons log:
[2016-05-31 18:00:14] [debug] ( prunsrv.c:1679) [ 3280] Commons Daemon procrun log initialized
[2016-05-31 18:00:14] [info] ( prunsrv.c:1683) [ 3280] Commons Daemon procrun (1.0.15.0 64-bit) started
[2016-05-31 18:00:14] [info] ( prunsrv.c:1580) [ 3280] Debugging 'CertAccordServer' service...
[2016-05-31 18:00:14] [debug] ( prunsrv.c:1374) [ 3280] Inside ServiceMain...
[2016-05-31 18:00:14] [debug] ( prunsrv.c:844 ) [ 3280] reportServiceStatusE: 2, 0, 3000, 0
[2016-05-31 18:00:14] [info] ( prunsrv.c:1127) [ 3280] Starting service...
[2016-05-31 18:00:14] [error] (rprocess.c:497 ) [ 3280] The user name or password is incorrect.
[2016-05-31 18:00:14] [error] ( prunsrv.c:1210) [ 3280] Failed to create process
[2016-05-31 18:00:14] [error] ( prunsrv.c:1210) [ 3280] The user name or password is incorrect.
[2016-05-31 18:00:14] [error] ( prunsrv.c:1536) [ 3280] ServiceStart returned 1
[2016-05-31 18:00:14] [error] ( prunsrv.c:1536) [ 3280] The user name or password is incorrect.
[2016-05-31 18:00:14] [debug] ( prunsrv.c:844 ) [ 3280] reportServiceStatusE: 1, 1066, 0, 1
[2016-05-31 18:00:14] [info] ( prunsrv.c:1582) [ 3280] Debug service finished with exit code 1
[2016-05-31 18:00:14] [error] ( prunsrv.c:1755) [ 3280] Commons Daemon procrun failed with exit value: 3 (Failed to run service as console application)
[2016-05-31 18:00:14] [error] ( prunsrv.c:1755) [ 3280] The user name or password is incorrect.
Here is the full command I use to add the service:
./tomcat8.exe \
//IS//MyServer \
--LogLevel Debug \
--Description "My service info" \
--DisplayName "My Server" \
--Install 'C:\Program Files\MyServer\tomcat\bin\tomcat8.exe' \
--LogPath 'C:\ProgramData\MyServer\tomcat\logs' \
--ServiceUser 'myuser#contoso.com' \
--ServicePassword test123 \
--StdOutput auto \
--StdError auto \
--StartImage "C:\Program Files\MyServer\java\bin\java.exe" \
--Startup auto \
--StartMode exe \
--StopMode exe \
--StartParams start \
--StopParams stop \
--StartClass org.apache.catalina.startup.Bootstrap \
--StopClass org.apache.catalina.startup.Bootstrap \
--JvmOptions "-Dcmb.productdir=C:\Program Files\MyServer;-Dcmb.datadir=C:\ProgramData\MyServer;-Dcatalina.home=C:\Program Files\MyServer\tomcat;-Dcatalina.base=C:\ProgramData\MyServer\tomcat;-Djava.endorsed.dirs=C:\Program Files\MyServer\tomcat\endorsed;-Djava.io.tmpdir=C:\ProgramData\MyServer\tomcat\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=C:\ProgramData\MyServer\tomcat\conf\logging.properties" \
--JvmMs 256m \
--JvmMx 1024m \
--Classpath "C:\Program Files\MyServer\tomcat\bin\bootstrap.jar;C:\Program Files\MyServer\tomcat\bin\tomcat-juli.jar;C:\ProgramData\MyServer\resource;C:\Program Files\MyServer\resource"
In place of --ServiceUser and --ServicePassword I've also tried --User and --Password. The failure is the same.
When I use --ServiceUser and go into Windows Services, find MyServer -> Properties -> LogOn -> This Account shows myuser#contoso.com. When I use --User the properties panel has This Account as blank and Local System selected.
The myuser#contoso.com is an AD account. On the local system where tomcat8 service is being added it has a group policy which gives it "Log On as a service".
I also verified that myuser#contoso.com is a valid account and the password matches by running this from a cmd prompt:
runas /noprofile /user:myuser#contoso.com notepad
Enter the password for myuser#contoso.com: test123
When I look at the Apache Commons procsrv C code I found this section which appears to be where the "Failed to create process" and then "The user name or password is incorrect" errors are triggered:
if (!LogonUserW(szUsername,
NULL,
szPassword,
bLogonAsService ? LOGON32_LOGON_SERVICE : LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&hUser)) {
/* Logon Failed */
apxLogWrite(APXLOG_MARK_SYSERR);
return NULL;
}
I wrote a simple C program with the above code and verified that if szPassword is NULL or not a match for the AD password for myuser#contoso.com I get "The user name or password is incorrect".
I can't think of anything else to try. I'm stuck. :(
Looking at the Apache Commons Daemon code, I see that the only time that Tomcat actually needs the user details is when it's starting as a separate executable - i.e. when you have installed it as -StartMode exe.
Looking at the way that tomcat is normally installed in service.bat, I see that this uses the JNI form of invocation - i.e. -StartMode jvm. This will not go through the problematic path and so should avoid your user/password problem.
Alternatively, if you actually need Tomcat to run as a separate executable... You can see in the same Apache Commons code linked above that it gets all its data from a combination of the command-line and the Windows Registry. Since you have installed your service with no command-line parameters, it will try to find the user and password in the registry. In addition, since you have not specified the User or Password on installation, it won't have saved them off to the registry either. It is therefore pulling in empty values.
So, you have two possible ways that you can resolve this problem:
Start up (and stop) in JVM mode, using -StartMode jvm when you install the service.
Specify both forms of User and Password when installing your service. This should put the extra data into the Registry and so make it available when the service tries to start.
You used an incorrect parameter name for your username and password.
--ServiceUser 'myuser#contoso.com' --ServicePassword
test123
It should be:
--User 'myuser#contoso.com'
--Password test123
OR
Try this https://superuser.com/a/842867
When entering commands, you should do so as Administrator. E.g. from Windows start menu, type in cmd, right click on the cmd.exe or Command Prompt it gives you, and select Run as administrator.
Install TomcatN as a service:
Just run tomcat's c:\path\to\TomcatN\bin\service.bat and give it a service name to use, i.e. Tomcat8. Or,
sc Create TomcatN binPath= "c:\path\to\TomcatN\bin\tomcatN.exe" displayName= "Apache Tomcat N"
Set the service to run as a specific user:
Most of the time you don't need this. But sometimes you need to access the Windows network as a registered user. For example, if you are taking advantage of some Active Directory functionality. It might work to use the following:
C:\path\to\tomcatN\bin\service.bat install TomcatN --user=George --password=abc123
But probably not. You can configure the service manually instead.
Manually configure the service to use a specific username and password:
From the Windows command prompt, you can use the services configurator. Some commands of interest:
sc
sc query TomcatN
sc qc TomcatN
sc config TomcatN obj= "MyHostName\George" password= "abc123"
Take care to note the space that comes after the equal signs in that last command.
Ensure the user has permissions:
Enter the gpedit.msc command. In the GUI that appears, navigate to
Local Computer Policy | ...
- Computer Configuration | ...
- Windows Settings | []Log on as a service
- Security Settings | ...
User Rights Assignment | ...
Double-click on Log on as a service and Add User or Group.... Type the shorthand for the username you want the service to use into the field, click Check Names, and press OK.
Confirm that TomcatN is running as intended:
You can use the following commands to start, stop, and check the status of the service:
net start TomcatN
net stop TomcatN
sc query TomcatN
Checking that the login works as intended
Make sure you've started the service running. Open Windows Task Manager and view the Processes tab. Click on Show processes from all users if necessary. TomcatN should be listed, with the username you specified next to it.
Credit goes to #andrewk
Resource Link:
How do I run Tomcat service as a specific user in Windows?
Run Tomcat Service as Different User on Windows 7
When I try and connect it my mysql database with JDBC in java, it doesn't go to my web server.
Here is the code
String dbtime;
String dbUrl = "jdbc:mysql://184.172.176.18:3306/dcsoft_dcsoft_balloon";
String dbUser = "myuser";
String dcPass = "mypass";
String dbClass = "com.mysql.jdbc.Driver";
String query = "Select * FROM users";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(dbUrl, dbUser, dcPass);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
dbtime = rs.getString(1);
System.out.println(dbtime);
}
con.close();
} catch(ClassNotFoundException e) {
e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
}
This code is supposed to go to my web server but it gives this error
java.sql.SQLException: Access denied for user 'dcsoft_dcsoft_java'#'jamesposse.force9.co.uk' (using password: YES)
jamesposse.force9.co.uk is the not the address im trying to connect to I'm trying to connect to 184.172.176.18:3306.
Thanks.
The hosts file contents is -
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
and lmhosts is -
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample LMHOSTS file used by the Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to computernames
# (NetBIOS) names. Each entry should be kept on an individual line.
# The IP address should be placed in the first column followed by the
# corresponding computername. The address and the computername
# should be separated by at least one space or tab. The "#" character
# is generally used to denote the start of a comment (see the exceptions
# below).
#
# This file is compatible with Microsoft LAN Manager 2.x TCP/IP lmhosts
# files and offers the following extensions:
#
# #PRE
# #DOM:<domain>
# #INCLUDE <filename>
# #BEGIN_ALTERNATE
# #END_ALTERNATE
# \0xnn (non-printing character support)
#
# Following any entry in the file with the characters "#PRE" will cause
# the entry to be preloaded into the name cache. By default, entries are
# not preloaded, but are parsed only after dynamic name resolution fails.
#
# Following an entry with the "#DOM:<domain>" tag will associate the
# entry with the domain specified by <domain>. This affects how the
# browser and logon services behave in TCP/IP environments. To preload
# the host name associated with #DOM entry, it is necessary to also add a
# #PRE to the line. The <domain> is always preloaded although it will not
# be shown when the name cache is viewed.
#
# Specifying "#INCLUDE <filename>" will force the RFC NetBIOS (NBT)
# software to seek the specified <filename> and parse it as if it were
# local. <filename> is generally a UNC-based name, allowing a
# centralized lmhosts file to be maintained on a server.
# It is ALWAYS necessary to provide a mapping for the IP address of the
# server prior to the #INCLUDE. This mapping must use the #PRE directive.
# In addtion the share "public" in the example below must be in the
# LanManServer list of "NullSessionShares" in order for client machines to
# be able to read the lmhosts file successfully. This key is under
# \machine\system\currentcontrolset\services\lanmanserver\parameters\nullsessionshares
# in the registry. Simply add "public" to the list found there.
#
# The #BEGIN_ and #END_ALTERNATE keywords allow multiple #INCLUDE
# statements to be grouped together. Any single successful include
# will cause the group to succeed.
#
# Finally, non-printing characters can be embedded in mappings by
# first surrounding the NetBIOS name in quotations, then using the
# \0xnn notation to specify a hex value for a non-printing character.
#
# The following example illustrates all of these extensions:
#
# 102.54.94.97 rhino #PRE #DOM:networking #net group's DC
# 102.54.94.102 "appname \0x14" #special app server
# 102.54.94.123 popular #PRE #source server
# 102.54.94.117 localsrv #PRE #needed for the include
#
# #BEGIN_ALTERNATE
# #INCLUDE \\localsrv\public\lmhosts
# #INCLUDE \\rhino\public\lmhosts
# #END_ALTERNATE
#
# In the above example, the "appname" server contains a special
# character in its name, the "popular" and "localsrv" server names are
# preloaded, and the "rhino" server name is specified so it can be used
# to later #INCLUDE a centrally maintained lmhosts file if the "localsrv"
# system is unavailable.
#
# Note that the whole file is parsed including comments on each lookup,
# so keeping the number of comments to a minimum will improve performance.
# Therefore it is not advisable to simply add lmhosts file entries onto the
# end of this file.
jamesposse.force9.co.uk is the machine that you're connecting from.
When MySQL complains Access denied for user 'dcsoft_dcsoft_java'#'jamesposse.force9.co.uk', it means that the user dcsoft_dcsof_java was not authorized to connect from the host jamesposse.force9.co.uk.
In MySQL, you are authenticated by the username you try to connect to, and the hostname you're trying to connect from. This is why you grant access to users like:
grant access to 'dcsoft_dcsoft_java'#'localhost' identified by 'whatever'
This user can only connect from the same machine as the MySQL server (e.g. from webapps hosted on the same machine, or when you SSH into the machine and use the mysql commandline from there).
If you want to grant access to a specific machine, identify it by hostname or IP address.
grant access to 'dcsoft_dcsoft_java'#'184.172.176.18' identified by 'whatever'
To grant access from anywhere on the internet, use '%' as the host:
grant access to 'dcsoft_dcsoft_java'#'%' identified by 'whatever'
This might be a mysql on redhat password issue. I'm not sure why it's not using the username you're providing it though, unless you're not actually using:
String dbUser = "myuser";
String dcPass = "mypass";
And using
dcsoft_dcsoft_java
as your username.
Can you give some more details on your environment?
In mysql make sure that you have whateverUserNameYourUsing#% otherwise, you'll get this error. You can also replace the % with the IP address and/or domain name, but it has to be every domain name your database will allow access from.