I am currently developing a CakePHP 2.4 app and trying to manage changes to my database table schemas with the schema manager. I figured out how to generate the schema and restore it, but is there a way to backup the entire database's schema with it? Seems like should be a method to solve this... Any thoughts?
Of course, use the schema dump command from the Cake Console.
It will write the entire schema to a .sql file and store it in App/Config/Schema.
Example of usage:
Console/cake schema dump --write filename.sql
(change 'filename.sql' to whatever the dump file should be called.)
This can also be find in the cake docs:
http://book.cakephp.org/2.0/en/console-and-shells/schema-management-and-migrations.html
There is actually a better way to handle this using the CakeDC Migrations Plugin, this gives you Rails type "migrations" that will help you snapshot your schema, it is an improvement to the cake schema dump method specified above and is actually developed by the CakePHP core team.
CakeDC Migrations
You can dump your schema using cake schema command
First of all you have to set the cake command path
In the windows system you have to set the path of the console/cake
Go to the cmd
Write the command "Console/cake schema generate" from this you can generate schema
After that if you want to dump in to the sql file So, You have to use following command "Console/cake schema dump --write filename.sql"
For more information click on below link
http://book.cakephp.org/2.0/en/console-and-shells/schema-management-and-migrations.html
Related
I lost my database since i moved servers.
I still have the migrations in my laravel folder. And i also have this rater.sql file in the root of my project. Is there a way i could get my database back with the migrations?
If you are using shared hosting you cant run command, so you can open your files in an FTP file manager (I prefer PHPStorm), then you can run below command as Hedam said:
php artisan migrate
now you can export the database to your localhost and import that on your hosting.
If you dumped your database, your data is lost.
You can though restore the data structure with
php artisan migrate
Obviously, we do not know what rater.sql contains, so I suggest you look if any data can be recovered from this file.
I am very new in Google app engine please help me to solve my problem
I have created one instance in Google cloud sql when I import SQL file then it shows me error like this.
ERROR 1227 (42000) at line 1088: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
How do I to add super privilege to my instance.
As stated at the Cloud SQL documentation:
The SUPER privilege is not supported.
You can take a look at this page that explains how to import data to a Cloud SQL instance.
I also faced the same issue. But the problem was in dumped sql database. When exporting the database use these flags
--hex-blob --skip-triggers --set-gtid-purged=OFF
Here is the complete documentation of how to do it (https://cloud.google.com/sql/docs/mysql/import-export/importing). Once the data is exported, it can be imported using command line, gcloud shell or there is an option of import in gcloud sql as well.
I used the import feature of gcloud sql console and it worked for me.
I ran into the the same error when backporting a gzipped dump (procured with mysqldump from a 5.1 version of MySQL) into a Google Cloud SQL instance of MySQL 5.6. The following statement in the sql file was the problem:
DEFINER=`username`#`%`
The solution that worked for me was removing all instances of it using sed :
cat db-2018-08-30.sql | sed -e 's/DEFINER=`username`#`%`//g' > db-2018-08-30-CLEANED.sql
After removal the backport completed with no errors. Apparently SUPER privilege is needed, which isn't available in Google Cloud SQL, to run DEFINER.
Another reference: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
Good luck!
i faced same issue you can try giving 'super permission' to user but isn't available in GCP cloud SQL.
The statement
DEFINER=username#`%
is an issue in your backup dump.
The solution that you can work around is to remove all the entry from sql dump file and import data from GCP console.
cat DUMP_FILE_NAME.sql | sed -e 's/DEFINER=<username>#%//g' >
NEW-CLEANED-DUMP.sql
After removing the entry from dump and completing successfully you can try reimporting.
For the use case of copying between databases within the same instance, it seems the only way to do this is using mysqldump, which you have to pass some special flags so that it works without SUPER privileges. This is how I copied from one database to another:
DB_HOST=... # set to 127.0.0.1 if using cloud-sql proxy
DB_USER=...
DB_PASSWORD=...
SOURCE_DB=...
DESTINATION_DB=...
mysqldump --hex-blob --skip-triggers --set-gtid-purged=OFF --column-statistics=0 -h $DB_HOST -u $DB_USER -p"$DB_PASSWORD" $SOURCE_DB \
| mysql -h $DB_HOST -u $DB_USER -p"$DB_PASSWORD" $DESTINATION_DB
Or if you just want to dump to a local file and do something else with it later:
mysqldump --hex-blob --skip-triggers --set-gtid-purged=OFF --column-statistics=0 -h $DB_HOST -u $DB_USER -p"$DB_PASSWORD" $SOURCE_DB \
> $SOURCE_DB.sql
See https://cloud.google.com/sql/docs/mysql/import-export/exporting#export-mysqldump for more info.
It's about the exporting of data. When you export from the console, it exports the whole Instance, not just the schema, which requires the SUPER privilege for the project in which it was created. To export data to another project, simply export by targeting the schema/s in the advanced option. If you run into could not find storage or object, save the exported schema to your local, then upload to your other project's storage, then select it from there.
In case somebody is searching for this in 2018 (at least august) the solution is:
Create a database. You can do this from UI, just go to Database menu and click "Create a database".
After you clicked "import" and selected your sql_dump (previously saved in a bucket), press "Show advanced options" and select your Db (not that advanced, are they?!). Otherwise, the default is the system mysql which, of course can not
support import.
Happy importing.
I solved this by creating a new database and in the SQL instance. (Default database is sys for mysql).
Steps(Non-cli version):
1) In GCP > SQL > Databases , create a new database e.g newdb
2) In your sql script, add: Use newdb;
Hope that helps someone
SUPER privilege is exclusively reserved for GCP
For you question, you need to import data into a YOUR database in which you have permission ..
OrientDB is using console command create DB by the way run console.bat file on "..\orientdb\bin\". However i need create a .bat separate file run like this command:
create database remote:localhost/test <root> <password> local graph
And run that .bat file by PHP
Thank for advance !
Based on the old documentation at https://code.google.com/p/orient/wiki/ImportFromRDBMS it seem that it is possible and is similar to what i want to do as well.
console.bat database.sql
where all your sql commands are in database.sql. The link about includes a sample for porting a full database over but don;t see why it should not work for similar scripts as well.
That said i have not tested this yet.
I am trying to create a model through Cake Bake command.
I am using windows and II7. I have set up the global variables on the system path so i can do "cake bake" on my Command Prompt.
I have my database config defined in App/config/database.php
Once i do it, i press M for Model, then i select the default database and the console shows this message:
Your database does not have any tables.
And i am not able to create any model for my project.
If i manually create a table on my DB, the error changes and it shows this: http://www.subirimagenes.com/imagen-picture-8000920.html
What's the problem with it? Of course i have no tables if i have just installed Cake!!
First, create your tables with, let's say, phpMyAdmin (localhost/phpmyadmin).
Then, if you have properly configured your database configuration in app/config/database.php you will see Models in your Bake script you can create.
refer below links to get step by step methodology in cake bake
http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html
http://www.jamesfairhurst.co.uk/posts/view/baking_with_cakephp
you can also check environment variable settings for this error
I have made changes to my model.py in Django and now I want to syncronize these changes. It's fine to delete the tables and re-create them. However, nothing seems to work. I am using sqlite3:
syncdb: only works first time, not with changes
"python manage.py sql my_site", followed by syncdb: I thought this would 'redo' it all, but the table still only has the old columns (or so I assume as I get an error when I try to access the table using my model).
Then I figure that I can access the database directly and delete the tables that way. However, I don't know how to get "in" to the DB where I can execute commands. Typing sqlite3 from the command prompt is not recognized. I also tried "python manage.py sql my_site", but I again get the message that sqlite3 is not recognized.
Suggestions?
First you have to install the command line tool for sqlite. On Ubuntu/Debian, you can simply do
sudo apt-get install sqlite3
On windows, you can download it from here: http://www.sqlite.org/download.html. Look for the one that looks like sqlite-shell-win32-xxx.zip.
Use it like this:
> sqlite3 /path/to/your/database
;show some help
.help
; list all databases
.databases
; clear the contents of a table
DELETE FROM <tablename>;
See also the command line reference: http://www.sqlite.org/sqlite.html
and the sqlite SQL reference: http://www.sqlite.org/lang.html.
Using the "ALTER TABLE" sql command, you can also add columns without deleting the entire contents of the table. To do this, compare the output of .schema in sqlite3, and the output of manage.py sql my_site to find out which columns you need to add.
An example:
ALTER TABLE "buildreport_series" ADD COLUMN "parameters" text
Use Django's built in database management tool:
python manage.py dbshell
And issue the required sql commands. The sql command will only print to stdout what the required sql is to create the current tables (as defined by the current models).