Cannot drop the table in PHDMYADMIN [duplicate] - mysql

I am using 000webhost.com and I am using phpMyAdmin there. I am getting this error from MySQL when I run my PHP script as the title says:
Column count of mysql.proc is wrong. Expected 20, found 16.
The table is probably corrupted.
Is there any solution for this?
<?php
$username="usrname";
$password="passwd";
$database="a1xxxxx_mydb";
$host="mysqlxx.000webhost.com";
mysql_connect($host,$username,$password);
#mysql_select_db($database) or die( "Unable to select database");
if (isset($_GET["userLatitude"]) && isset($_GET["userLongitude"])) {
$userLatitude=$_GET['userLatitude'];
$userLongitude=$_GET['userLongitude'];
$result = mysql_query("SELECT locationName, ( 6371 * acos( cos( radians(floatval( $userLatitude) )) * cos( radians( locationLatitude ) ) * cos( radians( locationLongitude ) - radians( floatval($userLatitude)) ) + sin( radians(floatval($userLongitude)) ) * sin( radians( locationLatitude) ) ) ) AS distance
FROM Location HAVING distance < 2 ORDER BY distance LIMIT 0 ,20") or die(mysql_error());
echo $result;
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["Location"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["locationName"] = $row["locationName"];
$product["locationInfo"] = $row["locationInfo"];
$product["locationLatitude"] = $row["locationLatitude"];
$product["locationLongitude"] = $row["locationLongitude"];
$product["locationPic"] = $row["locationPic"];
$product["city"] = $row["city"];
// push single product into final response array
array_push($response["Location"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
}
else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
mysql_close();
?>

I had this error as well. I fixed it by running
mysql_upgrade -u root -p
Also, restart the mysql service by running
service mysqld restart

I had the same problem when I updated XAMPP from xampp-osx-7.2.10 to 7.3.9 in MacOS Mohave. So the solution was:
Find the file mysql_upgrade in "Macintosh HD⁩ ▸ ⁨Applications⁩ ▸ ⁨XAMPP⁩ ▸ ⁨xamppfiles⁩ ▸ ⁨bin⁩" and double click on it.

This error happens when a bad upgrade is done. For example, it happens if you upgrade from 5.0 to 5.1 but don't run the mysql_upgrade script; or, in rare cases, it probably happens if you directly upgrade from 5.0 to 5.5. (Many people does this, but such updrages are not officially supported)
You say you are using a hosting service - well, I think that you should create a ticket and tell them about the problem. If you don't have the SUPER privilege, there is nothing you can do.
But if you have that right, simply run mysql_upgrade:
http://dev.mysql.com/doc/refman/5.1/en/mysql-upgrade.html

A similar error appeared in MySQL Workbench 8.0.21 after installing XAMPP 7.4.8 on Ubuntu 18.04. There were no problems using phpMyAdmin.
Error Code: 1558 Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 100108, now running 100413. Please use mysql_upgrade to fix this error
Solution:
sudo /opt/lampp/lampp start
/opt/lampp/bin/mysql_upgrade
Problem solved
Credits: There appear to be a bug in XAMPP - https://community.apachefriends.org/f/viewtopic.php?f=17&t=78386&sid=3d3824dd0b6aa2e33c3adc73c744b4b4

I had the same problem when I updated the mysql server from 5.5 to 5.7 in Debian 8 (jessie). In my case, it worked fine when I executed the follow command:
mysql_upgrade --force -uroot -p

I am using xampp on Ubuntu 20.04 and the my problem that return this same message error was solved with this solution:
Go to the xampp directory: cd /opt/lampp/
Go to the bin directory: cd bin
Execute the script: sudo ./mysql_upgrade
Credits: https://askubuntu.com/questions/1171409/how-to-run-mysql-upgrade-when-using-xampp

Although you may be correct about the necessity for upgrade, that's not the only reason this error occurs.
When the following is called with a query that returns 1 row
my $rv = $sth_indexq->fetchall_arrayref;
the following error is reported:
DBD::mysql::st execute failed: Column count of mysql.proc is wrong. Expected 20, found 16. Created with MySQL 50520, now running 50528. Please use mysql_upgrade to fix this error. at
...
However, the real cause of the error was use of fetchall_arrayref instead of fetchrow_arrayref. The following worked without errors:
my $rv = $sth_indexq->fetchrow_arrayref;
The data in $rv was only 1 level deep, not 2.
The mysql_upgrade solution may very well solve this issue, but the simple solution is know your data and use the right retrieval code.
J.White

I was using a windows 10 system and the solution that worked for me was
mysql_upgrade -u root -p
But you need to ensure that the path to the mysql_upgrade script which is present in the mysql/bin folder of your installation directory needs to be added in the environment variable path for this command to work

Hit on browser below command
/opt/lampp/bin/mysql_upgrade

For Linux
If you are using LAMPP, then you can fix it like -
sudo /opt/lampp/lampp start
/opt/lampp/bin/mysql_upgrade
else if you installed mysql separately, then you can like this -
mysql_upgrade -u root -p
service mysqld restart
For any other OS, you can simply go to bin directory of lampp installation & try to find mysql_upgrade file & execute it.

This my happen when eg. upgrading instead of migrating;
The part where it reads version check failed is the relevant part:
Version check failed. Got the following error when calling the 'mysql' command line client
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
FATAL ERROR: Upgrade failed
Obviously this is about an incompatible client version, but the mysql database is also different.
This here would be the current definition of the mysql.proc table ... which shows that enum column type has changed and that column aggregate has been added, since MariaDB 10.3.3.
Yet another problem is:
In MariaDB 10.4 and later, this table uses the Aria storage engine.
Downgrading the server to 5.x and deleting the InnoDB log files, then restoring table proc helped; (for MariaDB 5.x): https://github.com/google/mysql/blob/master/scripts/mysql_system_tables.sql

For me, the problem was caused by prefixing a table alias in front of COUNT() accidentally:
MariaDB> SELECT x.COUNT(1) FROM (SELECT 1) AS x;
ERROR 1558 (HY000): Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 100137, now running 100334. Please use mysql_upgrade to fix this error
MariaDB> SELECT COUNT(1) FROM (SELECT 1) AS x;
+-------------+
| COUNT(test) |
+-------------+
| 1 |
+-------------+
1 row in set (0.001 sec)
As you see, without the prefix before COUNT() it works. I was adding the table alias to all SELECT fields and, thereby, accidentally also added before the COUNT(). Whether this would give a different error message on a fresh database, I don't know, but the server has been running fine for years and by fixing the query the error goes away so... it seems like a runtime/syntax error to me, not an upgrade/restart problem like for the others in this thread.

can you use it for linux
sudo /opt/lampp/bin/mysql_upgrade

Related

Why am I getting a MySQL Syntax Error 1064 when using "SOURCE [filename]" in Laravel, but not when I run the same exact command from the command line?

I'm using Laravel with Homestead and MySQL. I have a database dump file that I want to restore on command. When I run this from the command line I don't get any errors:
mysql -h localhost -u homestead -psecret homestead < /home/vagrant/Data/local-db-reset.sql
My local-db-reset.sql file reads:
DROP DATABASE IF EXISTS homestead;
CREATE DATABASE homestead;
USE homestead;
SOURCE /home/vagrant/Data/local-db-snapshot.sql;
However, when I run the same commands in PHP from within a custom artisan command, I get a syntax error 1064 from MySQL:
$db = 'homestead';
$snapshot = '/home/vagrant/Data/local-db-snapshot.sql;';
DB::transaction(function() use ($db, $snapshot) {
DB::statement('DROP DATABASE IF EXISTS ' . $db . ';');
DB::statement('CREATE DATABASE ' . $db . ';');
DB::statement('USE ' . $db . ';');
DB::statement('SOURCE ' . $snapshot . ' ;');
});
The exact error reads:
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 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 'SOURCE /home/vagrant/Data/local-db-snapshot.sql' at line 1 (SQL: /home/vagrant/Data/local-db-snapshot.sql ;)
The 1064 error is triggered by the SOURCE command, even though it evaluates to the same exact command as in the sql script above. Why? How can I address this? I need to be able to do this from an artisan command, or at least from php somewhere.
Please note, I'm not in a situation where artisan migrate:fresh is an option, so please forget that approach. I really need to restore this exact snapshot.
A colleague of mine pointed out that SOURCE is not a SQL command, it's a meta-command to the mysql command-line client only. So I (essentially) refactored my code to use shell_exec() with the original mysql command-line command at the very top above, and things are working as they should be now.
This is likely because your webserver is using a different user to that which you use in your console.
I don't use Homestead myself, but with my setup, Apache runs under the user www-data.
You can check this by temporarily changing the permissions on your .sql file:
chmod 777 /home/vagrant/Data/local-db-snapshot.sql
If this resolves the issue, you need to work out the user your webserver is using. You should be able to do this by running sudo ps aux | grep nginx.
This should output something like this (NB: I substituted nginx for apache to suit my setup):
joundill#machine:~$ sudo ps aux | grep apache
root 1099 0.0 1.0 243836 40600 ? Ss 00:46 0:00 /usr/sbin/apache2 -k start
www-data 3395 0.0 2.4 253292 96744 ? S 01:36 0:01 /usr/sbin/apache2 -k start
joundill 4850 0.0 0.0 6436 672 pts/0 S+ 02:11 0:00 grep --color=auto apache
joundill#machine:~$
As you can see, the user www-data is running apache (in your case nginx). You'll need to grant this user access to your .sql file.

#1558 - Column count of mysql.proc is wrong. Expected 21, found 20. (XAMPP Mysql) [duplicate]

I am using 000webhost.com and I am using phpMyAdmin there. I am getting this error from MySQL when I run my PHP script as the title says:
Column count of mysql.proc is wrong. Expected 20, found 16.
The table is probably corrupted.
Is there any solution for this?
<?php
$username="usrname";
$password="passwd";
$database="a1xxxxx_mydb";
$host="mysqlxx.000webhost.com";
mysql_connect($host,$username,$password);
#mysql_select_db($database) or die( "Unable to select database");
if (isset($_GET["userLatitude"]) && isset($_GET["userLongitude"])) {
$userLatitude=$_GET['userLatitude'];
$userLongitude=$_GET['userLongitude'];
$result = mysql_query("SELECT locationName, ( 6371 * acos( cos( radians(floatval( $userLatitude) )) * cos( radians( locationLatitude ) ) * cos( radians( locationLongitude ) - radians( floatval($userLatitude)) ) + sin( radians(floatval($userLongitude)) ) * sin( radians( locationLatitude) ) ) ) AS distance
FROM Location HAVING distance < 2 ORDER BY distance LIMIT 0 ,20") or die(mysql_error());
echo $result;
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["Location"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["locationName"] = $row["locationName"];
$product["locationInfo"] = $row["locationInfo"];
$product["locationLatitude"] = $row["locationLatitude"];
$product["locationLongitude"] = $row["locationLongitude"];
$product["locationPic"] = $row["locationPic"];
$product["city"] = $row["city"];
// push single product into final response array
array_push($response["Location"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
}
else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
mysql_close();
?>
I had this error as well. I fixed it by running
mysql_upgrade -u root -p
Also, restart the mysql service by running
service mysqld restart
I had the same problem when I updated XAMPP from xampp-osx-7.2.10 to 7.3.9 in MacOS Mohave. So the solution was:
Find the file mysql_upgrade in "Macintosh HD⁩ ▸ ⁨Applications⁩ ▸ ⁨XAMPP⁩ ▸ ⁨xamppfiles⁩ ▸ ⁨bin⁩" and double click on it.
This error happens when a bad upgrade is done. For example, it happens if you upgrade from 5.0 to 5.1 but don't run the mysql_upgrade script; or, in rare cases, it probably happens if you directly upgrade from 5.0 to 5.5. (Many people does this, but such updrages are not officially supported)
You say you are using a hosting service - well, I think that you should create a ticket and tell them about the problem. If you don't have the SUPER privilege, there is nothing you can do.
But if you have that right, simply run mysql_upgrade:
http://dev.mysql.com/doc/refman/5.1/en/mysql-upgrade.html
A similar error appeared in MySQL Workbench 8.0.21 after installing XAMPP 7.4.8 on Ubuntu 18.04. There were no problems using phpMyAdmin.
Error Code: 1558 Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 100108, now running 100413. Please use mysql_upgrade to fix this error
Solution:
sudo /opt/lampp/lampp start
/opt/lampp/bin/mysql_upgrade
Problem solved
Credits: There appear to be a bug in XAMPP - https://community.apachefriends.org/f/viewtopic.php?f=17&t=78386&sid=3d3824dd0b6aa2e33c3adc73c744b4b4
I had the same problem when I updated the mysql server from 5.5 to 5.7 in Debian 8 (jessie). In my case, it worked fine when I executed the follow command:
mysql_upgrade --force -uroot -p
I am using xampp on Ubuntu 20.04 and the my problem that return this same message error was solved with this solution:
Go to the xampp directory: cd /opt/lampp/
Go to the bin directory: cd bin
Execute the script: sudo ./mysql_upgrade
Credits: https://askubuntu.com/questions/1171409/how-to-run-mysql-upgrade-when-using-xampp
Although you may be correct about the necessity for upgrade, that's not the only reason this error occurs.
When the following is called with a query that returns 1 row
my $rv = $sth_indexq->fetchall_arrayref;
the following error is reported:
DBD::mysql::st execute failed: Column count of mysql.proc is wrong. Expected 20, found 16. Created with MySQL 50520, now running 50528. Please use mysql_upgrade to fix this error. at
...
However, the real cause of the error was use of fetchall_arrayref instead of fetchrow_arrayref. The following worked without errors:
my $rv = $sth_indexq->fetchrow_arrayref;
The data in $rv was only 1 level deep, not 2.
The mysql_upgrade solution may very well solve this issue, but the simple solution is know your data and use the right retrieval code.
J.White
I was using a windows 10 system and the solution that worked for me was
mysql_upgrade -u root -p
But you need to ensure that the path to the mysql_upgrade script which is present in the mysql/bin folder of your installation directory needs to be added in the environment variable path for this command to work
Hit on browser below command
/opt/lampp/bin/mysql_upgrade
For Linux
If you are using LAMPP, then you can fix it like -
sudo /opt/lampp/lampp start
/opt/lampp/bin/mysql_upgrade
else if you installed mysql separately, then you can like this -
mysql_upgrade -u root -p
service mysqld restart
For any other OS, you can simply go to bin directory of lampp installation & try to find mysql_upgrade file & execute it.
This my happen when eg. upgrading instead of migrating;
The part where it reads version check failed is the relevant part:
Version check failed. Got the following error when calling the 'mysql' command line client
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
FATAL ERROR: Upgrade failed
Obviously this is about an incompatible client version, but the mysql database is also different.
This here would be the current definition of the mysql.proc table ... which shows that enum column type has changed and that column aggregate has been added, since MariaDB 10.3.3.
Yet another problem is:
In MariaDB 10.4 and later, this table uses the Aria storage engine.
Downgrading the server to 5.x and deleting the InnoDB log files, then restoring table proc helped; (for MariaDB 5.x): https://github.com/google/mysql/blob/master/scripts/mysql_system_tables.sql
For me, the problem was caused by prefixing a table alias in front of COUNT() accidentally:
MariaDB> SELECT x.COUNT(1) FROM (SELECT 1) AS x;
ERROR 1558 (HY000): Column count of mysql.proc is wrong. Expected 21, found 20. Created with MariaDB 100137, now running 100334. Please use mysql_upgrade to fix this error
MariaDB> SELECT COUNT(1) FROM (SELECT 1) AS x;
+-------------+
| COUNT(test) |
+-------------+
| 1 |
+-------------+
1 row in set (0.001 sec)
As you see, without the prefix before COUNT() it works. I was adding the table alias to all SELECT fields and, thereby, accidentally also added before the COUNT(). Whether this would give a different error message on a fresh database, I don't know, but the server has been running fine for years and by fixing the query the error goes away so... it seems like a runtime/syntax error to me, not an upgrade/restart problem like for the others in this thread.
can you use it for linux
sudo /opt/lampp/bin/mysql_upgrade

Error while installing Koha

I get this error when installing via the web installer, the error says:
DBIx::Class::Storage::DBI::_dbh_execute(): Data truncated for column 'type' at row 1 at /usr/share/koha/lib/Koha/Objects.pm line 101
Installed version is: 16.05.05.000
I installed using packages by following the instructions on this link: https://wiki.koha-community.org/wiki/Koha_on_Debian
The database I'm using is: MySQL database; and it is on the same machine as Koha.
Any idea please!
I was presented with the same error. It appears that the error is given in an enum column in the database. For MySQL you can solve it as follows (inside the MySQL database administrator):
SET GLOBAL sql_mode = '';
When setting the mode with an empty string '' you are telling MySQL not to take into account some errors that arise when inserting data.
MySQL can operate in different modes, some modes are more restrictive than others, for example, some modes do not allow certain operations, such as division by zero or restrict the way in which the dates are represented in the database.
To see how the server is, you must log into MySQL from the command line:
mysql -u root -p
If the MySQL server does not have a password (which is not recommended), omit the -p parameter. You can then check the mode with the following command
SELECT ##GLOBAL.sql_mode;
It will return more or less similar to this:
STRICT_TRANS_TABLES, NO_ENGINE_SUBSTITUTION
You can find more information on this at http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html
Source
install phpmyadmin on different port (say 81)
select koha_library database (where library is the instance)
select ‘search_filed’ table
press ‘structure’ tap
select 'type' column and then press 'change'
change the type to varchar and length to 255 (or you can change the type of column 'type'in table ‘search_filed’ from enum to varchar(255) using the terminal)
execute the following command in server terminal (login using mysql-u root -p ):
SET GLOBAL sql_mode='';
quit;
sudo service mysql restart && sudo service apache2 restart

Xammp MySQL Error

I am getting this error in my phpmyadmin after recently installing new local xammp server.. Can anybody help on this one?
Warning in .\libraries\dbi\DBIMysqli.class.php#261
mysqli_query(): (HY000/1030): Got error 9 "Bad file descriptor" from storage engine MyISAM
Backtrace
.\libraries\dbi\DBIMysqli.class.php#261: mysqli_query(
object,
string 'SELECT * FROM `mysql`.`db` LIMIT 1',
integer 0,
)
.\libraries\DatabaseInterface.class.php#246: PMA_DBI_Mysqli->realQuery(
string 'SELECT * FROM `mysql`.`db` LIMIT 1',
object,
integer 0,
)
.\libraries\check_user_privileges.lib.php#46: PMA_DatabaseInterface->tryQuery(string 'SELECT * FROM `mysql`.`db` LIMIT 1')
.\libraries\check_user_privileges.lib.php#395: PMA_checkRequiredPrivilgesForAdjust()
.\libraries\List_Database.class.php#17: require_once(.\libraries\check_user_privileges.lib.php)
.\libraries\PMA.php#17: require_once(.\libraries\List_Database.class.php)
.\libraries\common.inc.php#1089: include_once(.\libraries\PMA.php)
.\tbl_structure.php#14: require_once(.\libraries\common.inc.php)
You can run this executable file: mysql_upgrade.exe which is located inside this folder: XAMPP/mysql/bin.. I tried this and it worked.
I also received this recently on a fresh install.
Start MySQL from XAMPP or from the command line
Open command line [Windows] + [r], type "cmd" press [enter]
cd \xampp\mysql\bin
mysql_upgrade.exe
I found this is happening when I do several mysqldump's from MySQL servers and import them over to MariaDB. The update will check all of your mysql databases, fix table privileges, fixes table and database names, upgrades the tables, and flushes.
Old XAMPP packages used MySQL, in XAMPP 5.6.12 it was MySQL 5.6.26.
In the current XAMPP 5.6.14 however, they switched from MySQL to MariaDB 10.0.0.17.
Trying to upgrade the mysql database did not work correctly ("Can't create table..."/"Bad file descriptor"). While mysql_upgrade.exe was running, I had to regularly pause execution. This allowed it to run through.
i tried the solution posted here but it doesn't work (maybe due to Windows and MariaDB). I deciced to do a "quick & dirty" fix.
I navigated to my xampp folder, then /phpmyadmin/libraries/dbi/
Open DBIMysql.class.php - search for
if (! $server)
should be around line 138, insert before the if statement
$user = "your phpmyadmin username";
$password = "your phpmyadmin password";
Save the file and use the control to restart MySQL (alias MariaDB). Basically it just overwrites the variables user and password - it seems that the new MariaDB has a problem to receive the password and username in that class. After I did that, no more errors have occured.
But as I mentioned: be careful because this is a very dirty fix ;)
Hope it helps :)
The solution of this run as adminstrator mysql_upgrade.exe which is located inside this folder: XAMPP/mysql/bin.. I tried this and it work.
Deepesh Tripathi
vWarning in .\libraries\classes\Dbal\DbiMysqli.php#209
mysqli::query(): (HY000/1034): Index for table 'global_priv' is corrupt; try to repair it
Backtrace
DbiMysqli.php#209: mysqli->query(
string 'SELECT 1 FROM mysql.user LIMIT 1',
integer 0,
)
DatabaseInterface.php#219: PhpMyAdmin\Dbal\DbiMysqli->realQuery(
string 'SELECT 1 FROM mysql.user LIMIT 1',
,
integer 0,
)
DatabaseInterface.php#1713: PhpMyAdmin\DatabaseInterface->tryQuery(string 'SELECT 1 FROM mysql.user LIMIT 1')
SqlController.php#158: PhpMyAdmin\DatabaseInterface->isSuperUser()
Routing.php#192: PhpMyAdmin\Controllers\Sql\SqlController->__invoke(
,
array,
)
index.php#43: PhpMyAdmin\Routing::callControllerForRoute(
,
string '/sql',
,
,
)
Mình bị lỗi như thế này! Đã fix thành công ( I got this error! Successfully fixed)

MySQL says "Table 'database.table' doesn't exist"

I connect my Rails app to MySQL database, working with that and after turning off the laptop and starting Rails and MySQL server again, I get the error
ActionView::Template::Error (Mysql2::Error: Table 'database.table' doesn't exist: SHOW FULL FIELDS FROM `table`):
This is in Rails log.
When I log in into MySQL through the terminal
mysql -u root -p
choose a database and then try to display data from a table, like
mysql> select * from users;
ERROR 1146 (42S02): Table 'database.users' doesn't exist
I google this issue and found a temporarily solution, but this is not appropriate because it involves remove all old data in the respective database:
cd /usr/local/mysql/data
sudo rm -rf database_name
So I would like to ask you for help - how to properly figure out this issue?
Thank you
Looks like you're using rails, did you issue the command
rake db:migrate
And while you're in mysql I suggest you to get the list of available tables with:
show tables;