#1146 - Table 'phpmyadmin.pma__tracking' doesn't exist - sql

Having a problem opening any of my databases in phpMyadmin
I tried deleting a lot of old, irrelevant databases and may have in the process
deleted something I shouldn't have and was wondering what I could do to resolve the error
#1146 - Table 'phpmyadmin.pma__tracking' doesn't exist

All the phpMyAdmin tables are defined in the SQL dump that comes with the package in sql/create_tables.sql. You can import that file in it's entirety (will also re-create any other tables you might have dropped) or just create the missing table by running this query:
CREATE TABLE IF NOT EXISTS `pma__tracking` (
`db_name` varchar(64) NOT NULL,
`table_name` varchar(64) NOT NULL,
`version` int(10) unsigned NOT NULL,
`date_created` datetime NOT NULL,
`date_updated` datetime NOT NULL,
`schema_snapshot` text NOT NULL,
`schema_sql` text,
`data_sql` longtext,
`tracking` set('UPDATE','REPLACE','INSERT','DELETE','TRUNCATE','CREATE DATABASE','ALTER DATABASE','DROP DATABASE','CREATE TABLE','ALTER TABLE','RENAME TABLE','DROP TABLE','CREATE INDEX','DROP INDEX','CREATE VIEW','ALTER VIEW','DROP VIEW') default NULL,
`tracking_active` int(1) unsigned NOT NULL default '1',
PRIMARY KEY (`db_name`,`table_name`,`version`)
)
COMMENT='Database changes tracking for phpMyAdmin'
DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
Switch to the phpmyadmin database. You can then use the "SQL" tab to execute this query directly on the database.

I had this problem after installed XAMPP. I did the following:
In /opt/lampp/bin1 use ./mysql_upgrade -u root with option -p if you use a password.
In /opt/lampp/var/mysql/phpmyadmin rm all *.ibd files.
Import create_tables.sql in phpMyAdmin GUI or run it in console.

Had similar problem.
I created pma__ tables in my project db by clicking something in operations tab of that db.
Then I deleted my db, created new with the same name and got "table does not exist" problem.
Fixed it by executing modified sql/create_table.sql on my db. Had to delete phpmyadmin db creation and use from there.

I had this issue when I switched from mysql to maraidb. The solution was to do the following, run the create tables script from the console.
Get to the terminal
$ mysql -uroot -padmin
Then import the create phpmyadmin db and tables script, I got it from Oldskool's answer above. (READ it before running it)
MariaDB [(none)]> source create_tables_phpmyadmin.sql;
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.02 sec)
...
In case of exists error you may clear your previous phpmyadmin db that you had tried adding.

Related

How to generate the script of rename table using sqlpackage.exe?

I have Two Database some-db-dev & some-db-qa. Both the databases are identical to each other.
I have created a DACPAC File for both the databases. some-db-dev.dacpac and some-db-qa.dacpac respectively.(It had the Table as "A" and Column "Test" in it. It also had some dummy records in it.)
After this I have performed below steps:
Renamed the Table "A" to "ARenamed" from some-db-dev Database.
Generated the DACPAC of "some-db-dev" and Stored it with the name "some-db-dev"
I have fire below command :-
sqlpackage /a:Script /sf:"C:\Users\some.user\Desktop\some-db-dev.dacpac" /tf:"C:\Users\some.user\Desktop\some-db-qa.dacpac" /tdn:"some-db-qa" /op:"C:\Users\some.user\Desktop\diffscript.sql"
Observations :-
Instead of renaming the Table modified at Step 1. It generated the Script of creating the table as below.
`GO
PRINT N'Creating [dbo].[ARenamed]...';
GO
CREATE TABLE [dbo].[ARenamed] (
[Id] NCHAR (10) NULL,
[Name] NCHAR (10) NULL,
[Test] NCHAR (10) NULL
);`
Is there something wrong with the command that I am using ??
Any help will be appreciable.
To rename a table in SSDT you need to use the refactoring tools "right click on the table and do refactor-rename". What happens is this adds an entry to the "RefactorLog.xml" - if you have one of those then when a deployment is created an sp_rename is generated, other you will get what you see here a drop and then create.
See: https://the.agilesql.club/2016/09/refactoring-in-sql-server-data-tools-ssdt/
The last section "Renaming Objects" shows how to do it.
Ed
I think that you'll need to use MSBuild instead. That's an example how to generate script project vs database.
MsBuild.exe "PATH_TO_SQL_PROJ_FILE" ^
/p:SqlPublishProfilePath="PATH_TO_PUBLISH_PROFILE" ^
/p:UpdateDatabase=False ^
/t:Build,Publish

Jetbrains Datagrip 2017.1.3, force columns exported when dumping data to sql inserts file

I have an SQL server database with a lot of tables and data. I need to reproduce it locally in a docker container.
I have successfully exported the schema and reproduced it. When I dump data to an SQL file, it does not export automatically generated fields (Like ids or uuids for example)
Here is the schema for the user table:
create table user (
id_user bigint identity constraint PK_user primary key,
uuid uniqueidentifier default newsequentialid() not null,
id_salarie bigint constraint FK_user_salarie references salarie,
date_creation datetime,
login nvarchar(100)
)
When it exports and element from this table, I get this kind of insert:
INSERT INTO user(id_salarie, date_creation, login) VALUES (1, null, "example")
As a consequence, most of my inserts give me foreign key errors, because the ids generated by my new database are not the same as the ones in the old database. I can't change everything manually as there is way too much data.
Instead, I would like to have this kind of insert:
INSERT INTO user(id_user, uuid, id_salarie, date_creation, login) VALUES (1, 1, "manuallyentereduuid" null, "example")
Is there any way to do this with Datagrid directly? Or maybe a specific SQL server way of generating insert statements this way?
Don't hesitate to ask for more details in comments.
You need the option 'Skip generated columns' while configuring INSERT extractor.
It seems like Datagrip does not give you that possibility so I used something else : DBeaver. It is free and based on the Eclipse Environment.
The method is simple :
Select all the tables you want to export
Right click -> Export table data
From there you just have to follow the instructions. It outputs one file per table, which is a good thing if you have a consequent volumetry. I had trouble executing the whole script and had to split it when using Datagrip.
Hope this helps anyone encountering the same problem. If you find the solution directly in datagrip, I would like to know too.
EDIT : See the answer above

How can I create a SQLite3 database file using a SQL command file?

I have a file which contains some SQL commands, something that looks like this:
CREATE DATABASE IF NOT EXISTS `db_name`;
USE `db_name`;
CREATE TABLE IF NOT EXISTS `customers` (
`id` int(10) unsigned NOT NULL,
`f_name` varchar(50) DEFAULT NULL,
`l_name` varchar(50) DEFAULT NULL,
`company_name` varchar(200) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`phone` varchar(25) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `customers` (`id`, `f_name`, `l_name`, `company_name`, `email`, `phone`) VALUES
...
...
...
I'd like to use these commands to create an SQLite3 database file in order to use it easily with Python.
How do I do that on Ubuntu?
That isn't quite an SQL file, that contains a bunch of MySQL-specific stuff some of which SQLite will accept and some it won't. We'll start at the top.
You don't need create database or use with SQLite. If you want to create a database just name it when you run sqlite3 from the command line:
$ sqlite3 db_name.sqlt < your_sql.sql
If db_name.sqlt exists then it will be used, if it doesn't exist then it will be created. So create database and use are implied by how you run sqlite3. You might need to use a different extension depending on what Python wants to see.
The backticks for quoting are a MySQLism, double quotes are the standard quoting mechanism for identifiers. Lucky for you, SQLite will accept them so you can leave them alone.
SQLite won't know what int(10) unsigned means, you'll have to remove the unsigned before SQLite will accept it. SQLite also won't know what ENGINE=InnoDB DEFAULT CHARSET=utf8 means so you'll have to remove that as well.
You'll probably run into other things that MySQL is happy with but SQLite is not. You'll have to try it and fix it and try it and fix it until it works. Or try to find a tool that can translate between databases for you, I always do these sorts of things by hand or using one-off scripts so I don't know of any tools that can help you.
Basically above commands are for mysql or other database (most of these have to be tweaked in order to work with sqlite. Sqlite stores database in the form of file. Basically when you start sqlite it will create a file (if not present). You can create or open a database by typing
sqlite3 db
on command line. This statement create or open database named "db"

How do I create tables from my .sql file in SQL Server

How do I create a table in SQL Server from a .sql? I see the query statements and the data to be inserted into the table but how do I create the actual tables?
If the statements to create the tables aren't in the .sql file, then you will need to know their structure and create them, either by using a handwritten query, another .sql file or SQL Server Management Studio (SSMS).
In SSMS you can expand a database in the Object Explorer and then right click on "Tables" to select "New Table..." then you will get a UI for defining the columns you need.
With the context of your previous question you need to contact whoever supplied the .sql files and ask for a script to create the required tables. Or perhaps they should send you a copy(a backup) of the database.
You can run it from the command prompt using the command below:
sqlcmd -S myServer\instanceName -i C:\myScript.sql
http://msdn.microsoft.com/en-us/library/ms170572.aspx
This assumes that your .sql files contains the logic to create the needed tables.
You can create tables from a sql script like so.
CREATE TABLE MyTable1 (
MyString1 NVARCHAR(50) NOT NULL,
MyInt1 INT NULL NULL
)
GO
CREATE TABLE MyTable2 (
Id INT IDENTITY(1,1) NOT NULL,
Name NVARCHAR(50) NOT NULL,
PRIMARY KEY(Id)
)
GO
See http://msdn.microsoft.com/en-US/library/ms174979%28v=SQL.90%29.aspx for more info

SQL script syntax for multiple databases under one user

This is probably stupid simple, but for some reason I'm having trouble getting it to work. I have a typical import script I'm trying to run on a MS SQL server with one master user (as opposed to a single user with only access to one database).
When I run the .SQL script, it creates the database and then starts to create tables. Here's where it gets interesting. It's not creating the databases under the DB I just made. It's throwing the tables under the "System Databases" view and not restricting the table creation to the DB that was just created.
I have tried:
CREATE TABLE table_name
CREATE TABLE database_name.table_name
Maybe I'm overlooking something really easy. I don't usually run into this with MySQL with a single user mapped to one database, I think since the user can only see that one database, so MySQL assumes it must be the one to work with.
The difference now is that I'm using MSSQL 2008 and maybe it works a little differently and I'm overlooking something. Thanks for your help!
Tried this too. No luck. Says database doesn't exist when it tries to create the table. I would think being a top/down read of the query script it would first create the database, then try to create the table afterwards.
CREATE DATABASE DATABASENAME;
CREATE TABLE DATABASENAME.dbo.TABLENAME
(
field_one VARCHAR(100) NOT NULL,
field_two INT NOT NULL,
PRIMARY KEY(field_one)
)
This is a working example after getting it all figured out. This syntax works well and I don't need to specify the DBO pathing stuff before table names this way. Cleaner and got me the results I was looking for. Thanks everyone.
IF Db_id('DBNAME') IS NULL
CREATE DATABASE DBNAME;
GO
USE [DBNAME];
GO
CREATE TABLE TABLENAME
(
COL1 VARCHAR(100) NOT NULL,
COL2 INT NOT NULL,
PRIMARY KEY(COL2)
)
INSERT INTO TABLENAME
(COL1,
COL2)
VALUES('1234',1001),
('1234',1002),
('1234',1003),
('1234',1004)
It basically just does a check to make sure database is created before doing anything else, then sets the USE database to the one I'm working with. Everything else is just normal SQL, so have fun. Cheers!
Probably you need to include the USE sentence at the begining of your script in order to indicate the database as follows:
USE [database_name]
GO
By default SQL-SERVER use the master DB that´s listed under system databases.
Other way is to use the database prefix, but including the owner:
INSERT INTO database_name.dbo.table_name
INSERT INTO database_name..table_name