error #1146 in phpMyAdmin in XAMPP - php

I did something dumb. I'd imported the create tables sql file twice. That's not the worst part however. I then proceeded to trying to drop the duplicate tables from the phpMyAdmin database. This is all that loads up when I click on phpMyAdmin now:
Error
SQL query: Edit
SELECT `tables`
FROM `phpmyadmin`.`pma_recent`
WHERE `username` = '[myusername]'
MySQL said:
#1146 - Table 'phpmyadmin.pma_recent' doesn't exist
As in, just the above on an otherwise blank, white page.
EDIT
Everything returns to normal when I comment out the "Advanced Features" section in the config.inc.php file (the red exclamation signs are still beside everything, but I'm starting to wonder if that's just the default icon choice for phpMyAdmin 4.0.1). Once I uncomment them, the above returns. I've also noticed that the tables seems to be empty (maybe the reason for the exclamation signs?). Does that mean anything?

Check whether the tables inside phpMyAdmin database have two underscores __ after the pma prefix. If that is the case, update the entries in you config.inc.php with an additional underscore.

It looks like you accidentally dropped one or more of your built-in databases/tables that keep phpmyadmin running. The easiest solution is probably just to re-install XAMPP so you don't leave anything bugged by trying to do patchwork.
Just back up all of your created data.
I think specifically, you dropped the table that phpmyadmin stores your username in. Now you have no usernames stored in it and therefore you can't log into phpmyadmin.

I had the same problem, I'm not too sure why. Commenting out the advanced parts does work. Probably not the best way to go about it, but I'm sure that works for some people.

I got the same issue as you but I found a way to solve it.
from the create_tables.sql you got this:
-- Table structure for table pma_recent
CREATE TABLE IF NOT EXISTS pma__recent (
username varchar(64) NOT NULL,
tables text NOT NULL,
PRIMARY KEY (username)
)
COMMENT='Recently accessed tables'
DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
the table name (pma__recent)contents two underscore characters by default, just remove one of them and recreate all the tables again by copy/paste the script into the SQL tab for phpmyadmin window. You should do the same thing for the others table name.

Related

ERROR importing SQL Database in PHP Admin [duplicate]

Error
SQL query:
--
-- Database: `work`
--
-- --------------------------------------------------------
--
-- Table structure for table `administrators`
--
CREATE TABLE IF NOT EXISTS `administrators` (
`user_id` varchar( 30 ) NOT NULL ,
`password` varchar( 30 ) NOT NULL ) ENGINE = InnoDB DEFAULT CHARSET = latin1;
MySQL said:
#1046 - No database selected
need some help here.
You need to tell MySQL which database to use:
USE database_name;
before you create a table.
In case the database does not exist, you need to create it as:
CREATE DATABASE database_name;
followed by:
USE database_name;
You can also tell MySQL what database to use (if you have it created already):
mysql -u example_user -p --database=example < ./example.sql
I faced the same error when I tried to import a database created from before. Here is what I did to fix this issue:
1- Create new database
2- Use it by use command
3- Try again
This works for me.
If you're trying to do this via the command line...
If you're trying to run the CREATE TABLE statement from the command line interface, you need to specify the database you're working in before executing the query:
USE your_database;
Here's the documentation.
If you're trying to do this via MySQL Workbench...
...you need to select the appropriate database/catalog in the drop down menu found above the :Object Browser: tab. You can specify the default schema/database/catalog for the connection - click the "Manage Connections" options under the SQL Development heading of the Workbench splash screen.
Addendum
This all assumes there's a database you want to create the table inside of - if not, you need to create the database before anything else:
CREATE DATABASE your_database;
If you are doing this through phpMyAdmin:
I'm assuming you already Created a new MySQL Database on Live Site (by live site I mean the company your hosting with (in my case Bluehost)).
Go to phpMyAdmin on live site - log in to the database you just created.
Now IMPORTANT! Before clicking the "import" option on the top bar, select your database on the left side of the page (grey bar, on the top has PHP Myadmin written, below it two options:information_schema and name of database you just logged into.
once you click the database you just created/logged into it will show you that database and then click the import option.
That did the trick for me. Really hope that helps
For MySQL Workbench
Select database from Schemas tab by right mouse clicking.
Set database as Default Schema
Edit your SQL file using Notepad or Notepad++
add the following 2 line:
CREATE DATABASE NAME;
USE NAME;
Assuming you are using the command line:
1. Find Database
show databases;
2. Select a database from the list
e.g. USE classicmodels; and you should be off to the races! (Obviously, you'll have to use the correctly named database in your list.
Why is this error occurring?
Mysql requires you to select the particular database you are working on. I presume it is a design decision they made: it avoids a lot of potential problems: e.g. it is entirely possible, for you to use the same table names across multiple databases e.g. a users table. In order to avoid these types of issues, they probably thought: "let's make users select the database they want".
If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!
be careful about blank passwords
mysqldump [options] -p '' --databases database_name
will ask for a password and complain with mysqldump: Got error: 1046: "No database selected" when selecting the database
the problem is that the -p option requires that there be no space between -p and the password.
mysqldump [options] -p'' --databases database_name
solved the problem (quotes are not needed anymore).
Check you have created the database first which you want.
If you have not created the dataBase you have to fire this query:
CREATE DATABASE data_base_name
If you have already created the database then you can simply fire this query and you will be able to create table on your database:
CREATE TABLE `data_base_name`.`table_name` (
_id int not null,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (_id)
);
Solution with an Example
Error 1046 occurs when we miss to connect our table with a database. In this case, we don't have any database and that’s why at first we will create a new database and then will instruct to use that database for the created table.
# At first you have to create Database
CREATE DATABASE student_sql;
# Next, specify the database to use
USE student_sql;
# Demo: create a table
CREATE TABLE student_table(
student_id INT PRIMARY KEY,
name VARCHAR(20),
major VARCHAR(20)
);
# Describe the table
describe student_table;
quoting ivan n :
"If importing a database, you need to create one first with the same name, then select it and then IMPORT the existing database to it.
Hope it works for you!"
These are the steps:
Create a Database, for instance my_db1, utf8_general_ci.
Then click to go inside this database.
Then click "import", and select the database: my_db1.sql
That should be all.
first select database : USE db_name
then creat table:CREATE TABLE tb_name
(
id int,
name varchar(255),
salary int,
city varchar(255)
);
this for mysql 5.5 version syntax
I'm late i think :] soory,
If you are here like me searching for the solution when this error occurs with mysqldump instead of mysql, try this solution that i found on a german website out there by chance, so i wanted to share with homeless people who got headaches like me.
So the problem occurs because the lack -databases parameter before the database name
So your command must look like this:
mysqldump -pdbpass -udbuser --databases dbname
Another cause of the problem in my case was that i'm developping on local and the root user doesn't have a password, so in this case you must use --password= instead of -pdbpass, so my final command was:
mysqldump -udbuser --password= --databases dbname
Link to the complete thread (in German) : https://marius.bloggt-in-braunschweig.de/2016/04/29/solution-mysqldump-no-database-selected-when-selecting-the-database/
In Amazon RDS, merely writing use my-favorite-database does not work if that database's name includes dashes. Furthermore, none of the following work, either:
use "my-favorite-database"
use `my-favorite-database`
use 'my-favorite-database'
Just click the "Change Database" button, select the desired database, and voilà.
Although this is a pretty old thread, I just found something out. I created a new database, then added a user, and finally went to use phpMyAdmin to upload the .sql file. total failure. The system doesn't recognize which DB I'm aiming at...
When I start fresh WITHOUT first attaching a new user, and then perform the same phpMyAdmin import, it works fine.
Just wanted to add: If you create a database in mySQL on a live site, then go into PHPMyAdmin and the database isn't showing up - logout of cPanel then log back in, open PHPMyAdmin, and it should be there now.
For an added element of safety, when working with multiple DBs in the same script you can specify the DB in the query, e.g. "create table my_awesome_db.really_cool_table...".
jst create a new DB in mysql.Select that new DB.(if you r using mysql phpmyadmin now on the top it'l be like 'Server:...* >> Database ).Now go to import tab select file.Import!

Laravel PHPUnit failing on ALTER TABLE using SQLite

I have a migration which I made at the beginning of my project, basically adding a TEXT column called 'description' which is set to NOT NULL.
Now several months down the track I need to change that to allow null.
I can't use Laravel 5.5 change() function as I have a enum in my column list and it bugs out, so i need to add it as a raw query in a migration like so;
DB::statement('ALTER TABLE `galleries` MODIFY `description` TEXT NULL;');
When i do a php artisan migrate against my local mysql database it all works great, BUT when i try to run my test suite, it all breaks.
Im using SQLite for my test suite, and the error im getting is as follows;
PDOException: SQLSTATE[HY000]: General error: 1 near "MODIFY": syntax error
If anyone else has come up against this issue and fixed it, i would love to hear how you did it.
Thanks
SQLite only allows you to rename the table or add a column. The ALTER TABLE statement cannot change or remove columns.
In order to change or remove a column in SQLite, you need to create a new table with the desired schema, copy the data from the original table to the new table, delete the original table, and then rename the new table to the original name.
This is all abstracted out for you by Laravel and DBAL, so your best bet may be to get help with figuring out the issue with your enum column (though that would be a separate question).
You can read more about altering tables in the SQLite docs here.

Alter Tabled using PHP Query, Column Name doesn't show up in phpMyAdmin

This is my first post, and there is a similar post here: phpMyAdmin doesn't show added columns - Stack Overflow
But since no one has answered, I will ask here and provide more details in hoping to resolve this issue. I have a table in my database that I needed to be able to add additional columns to. I've done this using the following query:
$sql = "ALTER TABLE tablename ADD columnname INT(11)"; //Run the query....
This worked perfect on day one, however on day two when I tried to add an additional column via this php script, it appears to work from the phpMyAdmin Structure view. The column is in there with the correct columnname and datatype. However when I switch to the Browse view, there is no Column Name, just blank columns filled with "null" values. But, if you click on an individual row, it shows the correct column name, and a value (if one exists for that row).
I've tried running Analyze Table, as I read somewhere that that would update the Schema. However, I haven't had any success with that fixing it. I'd prefer to not have to delete the table and restart, especially if I run into this issue again. As this is my first post, I've tried to format everything correctly, but please forgive me if I didn't. Also, I can grab screenshots if anyone is having issues understanding my question.
if you can, restart mysql, it should flush everything, including mysql caches phpmyadmin may be using.

Mysql phpMyAdmin few questions:

I am quite new to the mysql phpMyadmin environment, and I would like to have some area
1. I need a field of text that should be up to around 500 characters.
Does that have to be "TEXT" field? does it take the application to be responsible for the length ?
indexes. I understand that when I signify a field as "indexed", that means that field would have a pointer table and upon each a WHERE inclusive command, the search would be optimized by that field (log n complexity). But what happens if I signify a field as indexed after the fact ? say after it has some rows in it ? can I issue a command like "walk through all that table and index that field" ?
When I mark fields as indexed, I sometimes get them in phpMyAdmin as having the keyname
for accessing the table by the indexed field when I write php, does it take an extra effort on my side to use that keyname that is written down there at the "structure" view to use the table as indexed, or does that keyname is being used behind the scenes and I should not care about it whatsoever ?
I sometimes get the keynames referencing two or more fields altogether. The fields show one on top of the other. I don't know how it happened, but I need them to index only one field. What is going on ?
I use UTF-8 values in my db. When I created it, I think I marked it as utf8_unicode_ci, and some fields are marked as utf8_general_ci, does it matter ? Can I go back and change the whole DB definition to be utf8_general_ci ?
I think that was quite a bit,
I thank you in advance!
Ted
First, be aware that this not per se something about phpmyadmin, but more about mysql / databases.
1)
An index means that you make a list (most of the time a tree) of the values that are present. This way you can easily find the row with that/those values. This tree can be just as easily made after you insert values then before. Mind you, this means that all the "add to index" commands are put together, so not something you want to do on a "live" table with loads of entries. But you can add an index whenever you want it. Just add the index and the index will be made, either for an empty table or for a 'used' one.
2)
I don't know what you mean by this. Indexes have a name, it doesn't really matter what it is. A (primary) key is an index, but not all indexes are keys.
3)
You don't need to 'force' mysql to use a key, the optimizer knows best how and when to use keys. If your keys are correct they are used, if they are not correct they can't be used so you can't force it: in other words: don't think about it :)
4)
PHPMYADMIN makes a composite keys if you mark 2 fields as key at the same time. THis is annoying and can be wrong. If you search for 2 things at once, you can use the composite key, but if you search for the one thing, you can't. Just mark them as a key one at a time, or use the correct SQL command manually.
5)
you can change whatever you like, but I don't know what will happen with your values. Better check manually :)
If you need a field to contain 500 characters, you can do that with VARCHAR. Just set its length to 500.
You don't index field by field, you index a whole column. So it doesn't matter if the table has data in it. All the rows will be indexed.
Not a question
The indexes will be used whenever they can. You only need to worry about using the same columns that you have indexed in the WHERE section of your query. Read about it here
You can add as many columns as you wish in an index. For example, if you add columns "foo", "bar" and "ming" to an index, your database will be speed optimized for searches using those columns in the WHERE clause, in that order. Again, the link above explains it all.
I don't know. I'm 100% sure that if you use only UTF-8 values in the database, it won't matter. You can change this later though, as explained in this Stackoverflow question: How to convert an entire MySQL database characterset and collation to UTF-8?
I would recommend you scrap PHPMyAdmin for HeidiSQL though. HeidiSQL is a windows client that manages all your MySQL servers. It has lots of cool functions, like copying a table or database directly from one MySQL server to another. Try it out (it's free)

Create Table Else Alter Table

This seems to be a simple problem, but after a while of searching I can't figure out the answer.
I currently have a MySQL table in my local database used by a webapp, and them same table on a database in a remote server. Right now, I'm using the CREATE TABLE IF NOT EXISTS command through PHP to create the table on the databases:
CREATE TABLE IF NOT EXISTS users (
`id` int(10) NOT NULL AUTO_INCREMENT,
`username` varchar(18) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
However, let's say I make a modification to the local database, adding a collumn, for example. It would be really annoying to have to go and change the remote database every time I change the local one. Is there an easier way to run code to create a table if it doesn't exist, and if it does exist, make sure it's structure matches that of the create table structure?
Here's an example, to make what I'm trying to convey a little clearer. Let's say on the local database I have a users table, and I decide that in my webapp I want to have another collumn, password. So I go to the local database and add a password collumn. Is there PHP/MySQL code I can run to check if the users table exists, and if it does, make sure it has a password collumn, and if not, add it?
What you are actually looking for are Migrations, e.g. you are looking for a Schema Management Tool that lets you manage your Database structure in versioned code diffs.
For instance, for your described scenario you would first create a script to create the table, e.g. 001_create_user_table.sql. Then you'd use the schema manager to connect and deploy these changes to your databases.
When you want to change or add something, you just write another script, for instance, 002_Add_Password_Column_To_User_Table.sql. Fill in just the code to do that change. Then run the schema manager again.
Typically, you tell the Schema Manager to go through all existing migrations files. On each run, the Schema manager will update a changelog table in the database, so when you run it, it will know which of your scripts it should apply.
The good thing is, you can add these migrations to your regular VCS, so you will always know which database schema you had at which version of your application. And you will have a proper changelog for them.
To directly answer your question you can create temporary procedures to detect field existence like using a query like this:
SHOW COLUMNS FROM table_name LIKE 'column_name';
However in the real world, database changes are general rolled into three scripts. A create script and two deltas one up and one down. Then the database is versioned so that you know at what state the database is in at any given time.
To specifically check for a password column you can use DESCRIBE:
$colExists = false;
$res = mysql_query('DESCRIBE `users`');
while ($row = mysql_fetch_assoc($res)) {
if ($row['Field'] == 'password') {
$colExists = true;
break;
}
}
if (!$colExists) {
// create column
}
However, you should check into replication or some other automated tool to see if they would be a better solution for you.
Follow these steps (you can easily implement this in PHP, I assumed that the name of the table is Foo)
1.) Run the following code:
desc Foo
2.) Based on the result of the first step you can make your create table command (and you should)
3.) Store your data from the existing table which will be replaced in a variable (Optional, you only need this if you can potentially use data from the old table)
4.) Modify the extracted rows from step 3.) so they will be compatible with your new definition (Optional, you only need this if you can potentially use data from the old table)
5.) Get the rows from your new Foo table
6.) Merge the results got in steps 4.) an 5.) (Optional, you only need this if you can potentially use data from the old table)
7.) Run a drop table for the old table
8.) Generate a replace into command to insert all your rows into the newly created Foo table (you can read more about this here)
After these steps, as a result, you will have the new version of the table. If your tables are too large, you can do a CREATE TABLE IF NOT EXISTS command and if that was not successful, run the alter command.
Also, you can make a library to do these steps and will use that in the future instead of solving the same problem several times.
EDIT:
You can connect the database using this function: mysql-connect (documentation here)
You can run a query using this function: mysql-query (documentation here)
Based on the first step you will get the field names (let's assume you store it in a variable called $bar) and you can use your result to generate your select command (connecting to the database where you have important data. It may be both):
$field_list = "1";
foreach ($bar as $key => $value)
$field_list.= ",".$bar[$key];
mysql_connect(/*connection data*/);
mysql_query("select ".$field_list." from Foo");
You can use your new resource to build up an insert command to insert all your important data after deletion recreation (about resources read more here, about how you can generate your insert you can read here, but I suggest that you should use replace into instead of insert which works like the insert, except that it replaces the row if it already exists, it's better here than an insert, read more here)
So, use mysql_connect and mysql_query, and the resource returned by the mysql_query function can be used for replace into later (I've linked now the URL's for everything you need, so I'm pretty sure you'll solve the problem.), apologies for being not specific enough before.

Categories