dp.opt file isn't creating when using "create database" - mysql

my problem is that when i use mysql to create database it described that it should create db.opt file, but it doesn't. How to fix that, i'm using mysql mysql-8.0.32-winx64 portable version
I have tried to enable that option innodb_file_per_table=ON in my.cnf file;
Also, i have tried to enable server with that argument "--skip-opt", and also imported it in my.cnf;
It seems that noone is faced that problem before and yeah i know that i doesn't really need that file it is just for my homework, by that file i should show that my databases have right CHARACTER SET and COLLATE.
For all that i using comand line interface.

MySQL 8.0 is working as designed. The db.opt file and other metadata files are no longer used, because this version of MySQL implements metadata in a different way.
https://dev.mysql.com/doc/refman/8.0/en/data-dictionary-file-removal.html
The metadata files listed below are removed from MySQL. Unless otherwise noted, data previously stored in metadata files is now stored in data dictionary tables.
...
db.opt files: Database configuration files. These files, one per database directory, contained database default character set attributes.
I have no idea what homework you would be doing that requires direct access to db.opt. That file is normally only used by internal code of MySQL 5. I've been using MySQL since 2001, but I've never had any need to read that file directly.

Related

How to include other .sql files in MySql command file?

I have multiple tables to create in my current project (each CREATE in its own .sql file) and the order of creation is important, so I'd like one file to create them all in the proper order when I create a new database. This is not a show-stopper, just an inconvenience. In MySQL (using phpMyAdmin) I'd like a single .sql file that will execute multiple other .sql files. I'm looking for something equivalent to Oracle's ability with the "#" sign (or keyword "start"):
#create_users.sql
#create_services.sql
Does MySql/phpMyAdmin have a similar command as Oracle to do this?
The mysql client has a command source that you can put into a .sql file. It reads another .sql file that you name.
This is analogous to the command of the same name in some POSIX shell scripting languages.
You might like to read this manual page to understand other built-in commands of the MySQL client: https://dev.mysql.com/doc/refman/en/mysql-commands.html
Re your comment: You asked in your question above if MySQL/phpMyAdmin has a similar command. MySQL does.
phpMyAdmin is not a product of MySQL, it's an independent community tool, and it does not have a similar command. phpMyAdmin has an import tab, with which you can upload one .sql file at a time.
The .sql files read by phpMyAdmin don't support all the same built-in commands that the command-line mysql client supports. For example, it does not support the source command, because that would require the web application phpMyAdmin to somehow read additional files from your computer. Web applications can't do that (and it's a good thing they can't).

How to import MYSQL database from Windows to production server

Disclaimer: I'm a total green horn.
I'm working with PhpStorm on Windows, which offers a convenient way of creating and managing databases during development. Unfortunately, now that I want to push to production, uploading the database to Cloadways (Digital Ocean Server) doesn't seem that simple.
Cloudways' Database Manager has an import function, that requires .gz (gzip) files. gzip files can not be created from directories, but on Windows mysql creates directories for each database and fills them with table files (.ibd).
I've read that you can compress directories into .tar files first and then gzip them (database.tar.gz) and that's what I tried. But when I try to import them with the database manager it only shows this:
Is there any way to do this?
Here's what you need to migrate your data to another MySQL server from your development machine: A text file named whatever.sql containing the definitions and contents of your tables (and views and stored functions and all your other database objects). This kind of text file is often called a mysqldump file. You'll find these files contain a whole mess of SQL statements, mostly CREATE TABLE and INSERT. They also contain some lines like
/*!40103 SET #OLD_TIME_ZONE=##TIME_ZONE */;
These look like comments, but when you load the file they're handled as SQL statements, so leave them alone.
You can use gzip(1) on your file to make it smaller, and Cloudways will handle it correctly. Things will work either with or without gzip.
How to export
With PhpStorm, open up the database panel and right-click on your database name (not the server name itself, but your application's database). You'll see a menu item Export with mysqldump. Click it. You can keep the default checkbox settings.
Then give a filename for your output and run the export.
I use PhpStorm on linux, so I'm not totally sure this export works on Windows. If it doesn't, download Ansgar Becker's free and excellent Windows MySQL client program called HeidiSQL. Right click on the database name then choose Export Database as SQL. Check the Create Tables box and choose Insert from the data pulldown.
How to import to production
Log into the production MySQL server.
Create the database and choose it. Cloudways looks like it does that for you. If not, issue these SQL statements.
CREATE DATABASE myDatabaseName;
USE myDatabaseName;
Use an appropriate tool to run all the SQL in your whatever.sql file. Cloudways looks like it does that for you too. If not, this command line, or something similar, might work.
mysql --user=yourMySQLUserName --password=secret\
--database=myDatabaseName\
--host=cloudways.example.com < whatever.sql
Your migration will be complete.
Extra bonus: If your whatever.sql file contains the initial state of your production database, you can put it into git (or other source control) and use it whenever you deploy a new instance of your software package.
Don't try to copy those .ibd files and other files managed by MySQL to another machine. If you do, you'll be sorry.

Where can I find my mySQL database (using locate doesn't help)?

First ever Stack Overflow post, thanks for your time. Any constructive criticism on how to post better, please just let me know. I have done a search on my query and have found similar posts, but I was unable to use the information within them to resolve my problem.
I have created a mysql database using the terminal window in my Ubuntu system (which I am also new to, having been a lifelong windows user). I used the following code in the terminal window:
$ mysql -u root -p
Then once in mysql, I did the following
CREATE DATABASE securities_master;
USE securities_master;
I created a user and tables in the database using some other code, that doesn't seem relevant here, so I won't bother posting. However, I then decided I would like to take a look at the tables in the database, so I downloaded an SQLite browser. It was at this point that I realized I could not find my database file.
I tried to find the answer on previous stack overflow posts, and tried the suggestions of:
locate sqlite
locate .db
locate .sqlite
locate securities_master
But unfortunately, none of these showed the file I was looking for. The only place I can think of would be what is called the 'root' directory in my computer, but the Ubuntu file manager system won't let me view it because it says I don't have permissions. Is this where it might be?
Could someone shed some light on where I might be able to find this file/database? I know it is definitely there because if I try to CREATE it again, I get the message that it can't because it already exists.
Thanks again.
sqlite and mysql are two different databases. You can't use sqlite on a mysql database. sqlite is a single-file database, in which users just open the file and read and write to it, while mysql is a more traditional relational database system with a server and a client, where the server manages the database (which is generally in a directory of files), while the client just connects to the server.
Where the mysql database is located my depend on your system, but it's usually in /var/lib/mysql. You can look in /etc/mysql/my.cnf for the configuration file, which should have a datadir option that refers to where the actual data for the database is stored.
You can check my.ini file to see where the data folder is located.
Usually there is a folder {mysqlDirectory}/data
MySQL data storage:
Commands.frm
Commands.myd
Commands.myi
The *.frm files contain the table definitions. Your *.myi files are MyISAM index files. Your *.myd files contain the table data.
as mentioned in the answer before mine, mysql and sqlite are two different systems.
You mention you used the cmd line mysql to create the database and then wanted to view the tables. If you're simply trying to see which table are created, in the same command line you used to Create the database you can run show tables;
If you're after a GUI for this, we'd need a bit more context. Is this ubuntu system a remote server, or are you using the desktop version?
You say you're a long time windows user, If you're using windows locally, I personally like SQLWorkbench for accessing my remote mysql servers.
EDIT: I just re-read your post and realised you're using local ubuntu desktop so me mentioning remote was silly, my bad! However, SQLWorkbench does have a ubuntu version at https://dev.mysql.com/downloads/workbench/

How do I locate my new mySQL database where I want it?

I'm on Windows using mySQL Workbench when I absolutely have to, otherwise ADO.
I'm experienced with Jet databases where you just create your mdb file, put it wherever you want whenever you want, and open the database with an ADO connection string containing the path to the database.
Now I've got to do this wretched mySQL thing ... for some reason I don't understand there's this Data directory where all the databases go and you can't change that when creating the database(?).
So I create my database as a shell (1 junk table to be deleted later, no records) and it's stuck in this worthless Data directory. Now I want to copy/paste this shell to where I really want it, and start working on it through ADO to create my "real" database ... but it doesn't work; my ADO connection string contains the new path and the connection opens with no errors, but all operations only change the copy in the Data directory.
Yes I have searched this topic, and the only "solutions" I see are to change the default Data directory in the ini file ... this seems silly and unworkable; what if I want to create another database and put it somewhere else?
Can someone please shed some light here?
Once you connect to the MySQL database as a user that can create databases, usually the root user after install, you can just write:
CREATE DATABASE my_database;
and that database will be created on the machine that's running the MySQL server process in the datadir that MySQL is using. There are default locations for these things, but you probably won't need to worry about them. You don't need to worry about where the files end up going as the first commenter says.
Here is the information for finding your my.cnf file on Windows. Once you find that file, update your datadir to the location that you want like this:
datadir="C:\New Data\Path"
and then stop your MySQL server and move your files. Restart the MySQL server after you copy all of the files in your current datadir to it. You can find your current datadir with the following command (connected to the server as the root user):
SHOW VARIABLES LIKE '%datadir%';
Make sure to stop the server before moving your files.
The CREATE TABLE documentation shows that you can create a table in a TABLESPACE that's outside of your datadir. First create a tablespace like the following:
CREATE TABLESPACE my_tablespace ADD DATAFILE 'C:\my_space';
which needs to be a single file if you want to use the InnoDB engine. You can then create tables in that table space by specifying it in your table's creation like:
CREATE TABLE new_table (a INT) TABLESPACE my_tablespace;
I haven't done this before, but it should work.

Migrate script from MySQL 4.0 to 4.1

I've exported a MySQL v4.0.25 script to a sql file and since I can't find an installer for 4.0 anymore the only option left is to use 4.1..
Now, I'm getting the common 1064 error since v4.0 doesn't have utf-8 (only latin-1) and v4.1 gives me a syntax error.
I'd be okay with editing the files manually but, one of the scripts is a file 12GB big and the other one is 5GB so I can't even find an editor able to open a file that large and a problem at hands with this migration (the files are that big because they are a copy of 2 production DBs with over 10years use).
How can I fix or bypass this problem? Any chance I can tell the import script to ignore the lines with errors (and I don't even know how many are there..)?
If it's still possible, dump the data structures in sql and the data tables in csv format using mysqldump --tab=path. This way, any modifications you will need to do will be on the much smaller sql file, keeping the large data files untouched. They you could later import the whole thing using mysqlimport command.
Alternatively, you could always use the mysql --force option for importing your sql file.
More information:
MySQL Reference Manual: mysqldump --tab=path option
MySQL Reference Manual: mysqlimport
MySQL Reference Manual: mysql --force
For manually editing the files:
If you are using Linux as your operating system, then there is a big variety of commands in your hand: more, less, sed, etc. sed is good for substitutions, similar to your question. A nice tutorial can be found at http://www.grymoire.com/Unix/Sed.html
In Windows, I sometimes use PowerShell. I had similar post on StackOverflow about "mysqldump without database name" where there is an example of how to replace a string in a dump file.