WSO2 GREG: My SQL setup issues - mysql

Following (https://docs.wso2.com/display/Governance450/Setting+up+with+MySQL) instructions I get an error:
mysql> -u regadmin -p -Dregdb < 'D:\Programs\wso2greg-5.1.0\dbscripts\mysql.sql';
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 regadmin -p -Dregdb < 'D:\Programs\wso2greg-5.1.0\dbscripts\mysql.sql'' at line 1
the steps are:
create database regdb character set latin1;
GRANT ALL ON regdb.* TO regadmin#localhost IDENTIFIED BY "regadmin";
FLUSH PRIVILEGES;
use regdb
show tables;
quit;
Iv'e confirmed drivers copied across - mysql_connector_java_5.1.38_bin_1.0.0.jar.
Iv'e confirmed default datasource updated - master-datasources.xml.
I didn't config any new datasources - I dont think I need them.
I then attempted to create database tables but get error above. Running "wso2server.bat -Dsetup" just generates following exception, which I assume is because I have no tables.
[2015-12-10 18:00:41,251] ERROR {org.wso2.carbon.user.core.util.DatabaseUtil} - Database Error - Incorrect string value: '\xE2\x80\x91200...' for column 'UM_DESCRIPTION' at row 1 java.sql.SQLException: Incorrect string value: '\xE2\x80\x91200...' for column 'UM_DESCRIPTION' at row 1
I'm guessing its going to be something trivial - I just don't see it. Ive tried playing around with the mysql syntax but to no avail. I note Governance450 docs say the tables are auto created. I assume the 460 is a valid correction?
-- update
part solved: not sure exactly what was wrong above (if anything). But following did create tables: (> from dos prompt, mysql> from mysql prompt)
> mysql -u root -p
--mysql> drop database if exists regdb;
mysql> create database regdb character set latin1;
--mysql> DROP USER ‘regadmin’#‘localhost’;
mysql> CREATE USER 'regadmin'#'localhost' IDENTIFIED BY 'regadmin';
mysql> GRANT ALL PRIVILEGES ON regdb.* TO 'regadmin'#'localhost';
> mysql -u regadmin -p
mysql> use regdb
mysql> source D:\Programs\wso2greg-5.1.0\dbscripts\mysql.sql;
mysql> show tables;

The steps I followed that eventually worked for me were:-
> mysql -u root -p
--mysql> drop database if exists regdb;
mysql> create database regdb;
--mysql> DROP USER ‘regadmin’#‘localhost’;
mysql> CREATE USER 'regadmin'#'localhost' IDENTIFIED BY 'regadmin';
mysql> GRANT ALL PRIVILEGES ON regdb.* TO 'regadmin'#'localhost';
> mysql -u regadmin -p
mysql> use regdb
mysql> source D:\Programs\wso2greg-5.1.0\dbscripts\mysql.sql;
mysql> show tables;
where
Dos prompt >
mysqlprompt mysql>

Related

In MySQL SERVER 8.0 the PASSWORD function not working

Error while executing the PASSWORD function in MySQL Server version 8.0.12
I have the following query:
SELECT *
FROM users
WHERE login = 'FABIO'
AND pwd = PASSWORD('2018')
LIMIT 0, 50000
I am getting this error:
Error Code: 1064. 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
If you need a replacement hash to match the password() function, use this: SHA1(UNHEX(SHA1()));
E.g.
mysql> SELECT PASSWORD('mypass');
+-------------------------------------------+
| PASSWORD('mypass') |
+-------------------------------------------+
| *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4 |
+-------------------------------------------+
and replacement that gives the same answer in version 8:
mysql> SELECT CONCAT('*', UPPER(SHA1(UNHEX(SHA1('mypass')))));
+-------------------------------------------------+
| CONCAT('*', UPPER(SHA1(UNHEX(SHA1('mypass'))))) |
+-------------------------------------------------+
| *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4 |
+-------------------------------------------------+
OP's MySQL Server version is 8.0.12. From MySQL Documentation, PASSWORD function has been deprecated for version > 5.7.5:
Note
The information in this section applies fully only before MySQL 5.7.5,
and only for accounts that use the mysql_native_password or
mysql_old_password authentication plugins. Support for pre-4.1
password hashes was removed in MySQL 5.7.5. This includes removal of
the mysql_old_password authentication plugin and the OLD_PASSWORD()
function. Also, secure_auth cannot be disabled, and old_passwords
cannot be set to 1.
As of MySQL 5.7.5, only the information about 4.1 password hashes and
the mysql_native_password authentication plugin remains relevant.
Instead, of the PASSWORD function, you can use much better and secure encryption functions from here. More details from the MySQL server team can be seen here.
With MySQL 8.0.22, I had to do the following:
update /etc/mysql/my.cnf and add lines:
[mysqld]
skip-grant-tables
restart mysql and run some queries:
> systemctl restart mysql
> sudo mysql
mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';
FLUSH PRIVILEGES;
mysql> exit;
log in again and update the password:
> mysql -u root
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH caching_sha2_password BY 'my password';
mysql> FLUSH PRIVILEGES;
update /etc/mysql/my.cnf and remove the line skip-grant-tables
> systemctl restart mysql
Finally, test
> mysql -u root -p
you may create another function that is similar to PASSWORD
SET GLOBAL log_bin_trust_function_creators = 1;
delimiter $$
CREATE FUNCTION PASSWORD2 (pass_in varchar(50)) RETURNS varchar(50)
BEGIN
declare n_pass varchar(50);
set n_pass = CONCAT('*', UPPER(SHA1(UNHEX(SHA1(pass_in)))));
return n_pass;
END$$
Then
SELECT PASSWORD2("my_super_scret_password") FROM MyUserTable ....

CREATE USER MySQL

Error with dropping tables:
SQL query:
DROP user IF EXISTS 's01'#'%';
MySQL said: Documentation
#1064 - 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 'if exists 's01'#'%'' at line 1
Error without dropping tables:
SQL query:
/*Students*/ CREATE User 's01'#'%' IDENTIFIED BY 'pw1';
MySQL said: Documentation
#1396 - Operation CREATE USER failed for 's01'#'%'
Example of some of my code:
Drop user if exists 's01'#'%';
flush privileges;
/*Students*/
Create User 's01'#'%' Identified by 'pw1';
I don't exactly know what is wrong. I looked it up and it said add flush privileges, but I still get the same two errors.
Check your version of mysql with select version();. The IF EXISTS option for DROP USER was added in 5.7. If you're not using 5.7, then that likely explains your first error.
Check if the user exists by querying mysql.user table.
select user, host from mysql.user where user = 's01';
Also since you are not specifying a hostname, just execute
DROP user IF EXISTS 's01';
Create User 's01' Identified by 'pw1';
The wildcard host (#'%') is implied.
Also execute SHOW GRANTS to verify that your user has the correct privileges to create and drop users.

mysql errors to authenticate and create a table

I have not been introduced to mysql, but had to work with it. I installed it and tried to run this:
mysql> CREATE TABLE h7vsk1200001 (quid VARCHAR(15), suid VARCHAR(15), iden FLOAT, alen INT, mism INT, gapo INT, qsta INT, qend INT, ssta INT, send INT, eval FLOAT, bits INT);
Which I understand is the basis for a table, with its names for columns and its datatypes. Whenever I run it, I get this error message:
bash: error sintáctico cerca del elemento inesperado `('
By the way, I'm using Ubuntu 14.04 if that matters. Also, if I try to run the CREATE TABLE command without arguments I get:
$ mysql> CREATE TABLE
ERROR 1045 (28000): Access denied for user 'carlos'#'localhost' (using password: NO)
Consider that I have little experience with bash and no experience with mysql (as you may have denoted)
You first need to launch the mysql shell. You can't run queries like this in bash: you need to use a MySQL client. You're getting the first error because bash is trying to parse the parentheses, and the second error is the result of you running the mysql command while piping (>) the output to a new file called CREATE.
Note you're getting the ACCESS DENIED because you apparently don't have access as the user carlos without a password. Use mysql -u myusername -p to log in with username myusername and to have mysql prompt for a password.
thom#lethe-arch:~$ # bash shell
thom#lethe-arch:~$ mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 443
Server version: 10.0.14-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.01 sec)
mysql> -- type queries here
(Note: MariaDB is a fork of MySQL and behaves exactly the same)
Seems you have to create a user 'carlos' and allow necessary permissions like:
mysql> use mysql;
mysql> CREATE USER 'carlos'#'localhost' IDENTIFIED BY 'yourpassword';
mysql> GRANT ALL PRIVILEGES ON . TO 'carlos'#'localhost' WITH GRANT OPTION;

MYSQL error: Can't create database 'publications'; database exists

I run this command in mysql:
mysql > show databases;
My database called publications is there so I want to use it:
mysql > USE publications
But I get an error:
ERROR 1049 (42000): Unknown database 'publications'
mysql > CREATE DATABASE publications;
ERROR 1007 (HY000): Can't create database 'publications'; database exists
Have I corrupted something? It is on XAMPP on thumb drive. What does this error mean?
you may not have permissions. open up the mysql database, and double check that mysql.db table has the user you are logged in as set up to read, write, etc.. as appropriate. after changing permissions, don't forget to FLUSH PRIVILEGES

How can I create a MySQL-database

I tried to create a database by the following command:
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP,
-> CREATE TEMPORARY TABLES,SHOW VIEW,CREATE ROUTINE,ALTER ROUTINE,
-> EXECUTE,CREATE VIEW,EVENT,TRIGGER
-> ON {projekti_db}.*
-> TO '{asiakas}'#'localhost';
and got the following error message
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 '{projekti_db}.*
TO '{asiakas}'#'localhost'' at line 4
I have MySQL 5.1.37. What am I doing wrong?
You are trying to assign roles to a user on a certain database. To create a database, use
CREATE DATABASE NAME;
That syntax doesn't create a database, it grants db privileges to a user.
To create a database, you'd use:
CREATE DATABASE projekti_db;
See here for a quick cheat sheet for MySQL.
#
# First create the Database
#
CREATE DATABASE projekti_db;
#
# Then Create the User that will access that database
#
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP,
CREATE TEMPORARY TABLES,SHOW VIEW,CREATE ROUTINE,ALTER ROUTINE,
EXECUTE,CREATE VIEW,EVENT,TRIGGER
ON projekti_db.*
TO 'asiakas'#'localhost';
#
# Now verify that the user asiaskas can access the projekti_db only from localhost
#
SHOW GRANTS FOR 'asiakas'#'localhost';
Give it a Try !!!