Hot questions for Using Ubuntu in mysql

Question:

package practice;

import java.sql.*;
import java.util.Properties;

public class DBTEst
{

  private static final String dbClassName = "com.mysql.jdbc.Driver";

  private static final String CONNECTION =
                          "jdbc:mysql://127.0.0.1/emotherearth";

  public static void main(String[] args) throws
                             ClassNotFoundException,SQLException
  {
    System.out.println(dbClassName);
    Class.forName(dbClassName);

      Properties p = new Properties();
    p.put("user","paulr");
    p.put("password","welcome");

    Connection c = DriverManager.getConnection(CONNECTION,p);

    System.out.println("It works !");
    c.close();
    }
}

i am new to database and so to sql.. i just configured the mysql with eclipse in ubuntu OS. but when i am trying to run the program i am getting the error like below.

com.mysql.jdbc.Driver
Exception in thread "main" java.sql.SQLException: Access denied for user 'paulr'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2526)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at practice.DBTEst.main(DBTEst.java:32)

i have found the same question in the forum but didn't solved my issue ...may it's due to OS change if not that pls forgive my ignorance and please guide through this..thanks for your help...root password i've set while installing mySQL is "welcome"..


Answer:

Either you did not set up the user paulr correctly in MySQL when you set it up, or you might have made the common mistake of overlooking that fact that MySQL does account access based on the client's IP address or hostname. Many people forget to include localhost and/or 127.0.0.1 in the user setup.

See https://stackoverflow.com/a/26234768/639520

Question:

I am developing a JSP, Servlet (pure jsp and servlet) application with hibernate.

I know that in "most" linux systems, the MySQL table names and database names are case sensitive, while in windows and Apple it is the other way around. I just learnt this in the hard way, ended up replacing table names in database and my java code.

However I can only test in Ubuntu. I do have "column" names with mixed cases. For an example, some columns of the table "employee" are idEmployee, FirstName, LastName, HomeAddress, PhoneNumberetc.

I know ubuntu is not making trouble with the case sensitivity of table "column" names, but what about other linux systems? Is there any linux/unix OS where it is case sensitive for the "column names" ?


Answer:

I don't think you have to worry. The documentation is clear that column aliases are not case sensitive:

Column, index, stored routine, and event names are not case sensitive on any platform, nor are column aliases.

. . .

By default, table aliases are case sensitive on Unix, but not so on Windows or OS X.

If I had to speculate why the case sensitivity follows the default case sensitivity of the underlying operating system, I would guess that under some circumstances (particularly long ago when MySQL was being developed), tables are stored in files under their own names. Now it is controlled by the lower_case_table_names system variable, which simply has different defaults on different operating systems.

Question:

Using Ubuntu 15.04, Eclipse Mars and JDBC MySQL Connector. Testing a Web Service (Maven project) that, upon deployment, builds several databases and tables. On first test, built just fine - thus, no code posted because there are no errors of syntax.

Before second test, however, I deleted all db directories under /var/lib/mysql. On running second test, Eclipse gives me an error stating that my tables can't be created because they already exist. Tried forcing reload of /etc/init.d/mysql, clearing query cache, as well as "DROP TABLE IF EXISTStable;" before issuing the CREATE TABLE query. What am I doing wrong?


Answer:

I deleted all db directories under /var/lib/mysql.

Don't do that.

The correct way to remove a database is to DROP DATABASE foo;. Tinkering with the files in /var/lib/mysql requires that you Know Exactly What You're Doing™.

What you have probably done is left tables stranded in the data dictionary.

What you probably can do is recreate the database manually with CREATE DATABASE foo; then try dropping it. Failing that, you may need to (from the shell, not from mysql) sudo mkdir /var/lib/mysql/foo then sudo chown -R mysql:mysql /var/lib/mysql/foo and then try DROP DATABASE foo;. Failing that, restart the server and see if it is any happier after that if you try to drop the database once again.

Note that if you are not using the MySQL command line client, you should run the query SHOW WARNINGS; after each query above -- some clients do not tell you when warnings occur and they can contain useful troubleshooting info.

Also, SELECT @@ERROR_LOG;. Read the log file on your server at the path indicated.

Question:

I was working on a small project (mostly for fun) on java with Eclipse Neon (and window builder), in which I had to connect to MySQL and retrieve certain info. In windows it worked great, I was able to connect, get the info, etc. But then I switched to Linux Ubuntu 16.04 and it just won't connect to MySQL. I already have the connector's path built and all that. I have no idea on what's happening or how to fix it, since I'm quite new to java programming (or programming in general) and haven't read any books about it. Below I'll leave some of the code (at least what I think is important).

Edit:

import java.awt.EventQueue;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class Test extends JFrame {

    Connection Con;
    Statement Sent;

    private JPanel contentPane;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Test frame = new Test();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/BDConductores?" + "user=root&password=PanXo_666");
                Statement st = con.createStatement();
                ResultSet result = st.executeQuery("select * from Proyectos");

                while (result.next()) {

                }

        } catch (ClassNotFoundException e) {
            System.out.println("Driver not found");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    public Test() {
        PrepararBaseDatos();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
    }

    void PrepararBaseDatos() {
        try {
            String controlador = "com.mysql.jdbc.Driver";
            Class.forName(controlador).newInstance();
            String servidor = "jdbc:mysql://localhost/BDConductores/";
            String usuarioDB = "root";
            String passwordDB = "PanXo_666";

            Con = DriverManager.getConnection(servidor, usuarioDB, passwordDB);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error al cargar controlador");
        }
        try {
            Sent = Con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error al cargar controlador");
        }
    }
}

and there's no error message, (besides the one in the code) it just won't load the controller and i have no idea what happens :c


Answer:

at the end I was able to see what was wrong... I wrote the wrong server name. it wasn't like this:

String servidor = "jdbc:mysql://localhost/BDConductores/";

it was like this:

String servidor = "jdbc:mysql://127.0.0.1:3306/BDConductores?";

So now my program connects to my database with no problems