"Learn SQL The Hard Way" - How to Setup Properly for Beginner? - mysql

I am a beginner attempting to learn SQL with Zed Shaw's "How to Learn SQL the Hard Way"
In excercise 0: The Set up, he states:
Then, look to see that the test.db file is there. If that works then you're all set.
But when I run the command,
sqlite> create table test (id);
sqlite> .quit
the execution runs, but it doesn't create a test.db file. I looked in the same folder as where the sqlite3.exe file is and I see nothing.
I attempt to see if I can continue without this step, then - In his next exercise, "Excercise 1: Creating Tables":
I input his commands, but when attempting to run sqlite3 ex1.db < ex1.sql, it gives me an error.
I even tried putting the create table command and saving it as a '.sql' file into the same folder as sqlite3.exe.
How can I set this environment up properly? Can someone explain this on an "easy to grasp" level? Any response is appreciated**
Edit 1
I'm not exactly sure how Zed Shaw how he wants his learners to use SQLite 3, Maybe I can go into some research but I just don't understand why he leaves such a large gap of assumption that everyone knows what to do for the set up process...

I had this exact problem. I am using windows 7.
From this website: http://www.sqlite.org/download.html
I used the:
"sqlite-tools-win32-x86-3130000.zip
(1.51 MiB) A bundle of command-line tools for managing SQLite..."
under the "Precompiled Binaries for Windows" heading.
My helper directed me to open the file named "sqlite3" after I'd extracted the files from the zip file. It brought up a black window, in the command line style, showing some text, and then the familiar sqlite> prompt.
Then he had me input:" .save data_base_name.db " (I chose to have my database be named 'thedatabase'.)
which created a file in the same folder as the sqlite3 file, called "data_base_name" as a "Data Base File".
That's where I'm at so far, I'll post updates as I have them.

Related

Error executing SQL script; The process cannot access the file because it is being used by another process:'C:\\Users\\......\....cnf'

I am trying to run a script to import data into MySQL. When I tried, this error shown up. I have searched for a workaround but none is helping. I deleted all the related .cnf file in the said path after a few attempts on trying to run the script but it kept on creating a new one. I have no other means of importing the data besides running that script. Terribly sorry if I somehow really ask a silly question about this but I am new with SQL, stuck and need help on the matter. Thanks in advance.
i have the same error as you, I've manage to solve it on my end by following these steps:
Rather than doing "run sql script", do "open sql script"
After the script open, Execute all (the lightning btn beside the save icon)
Hope this will work for you too!
I ran into this problem as well and, like #Alexandre-St-Amant, the size of my script prohibited opening the script as #vika suggests.
Before noticing #Kwaadpepper's suggestion, I tried using connecting to my database through mysqlsh.exe, then used SOURCE <data_file>. This has the added benefit of allowing linked scripts using SOURCE, solving #Adrian-Moldovan's issue.
Of course, this does not use mysql-workbench to solve the problem.
I had same problem with my sql script.
You may try reinstall the client and workbench. You should follow one version of applications. After that actions my script has worked.
My sql file was really big and I was not able to copy the contents or load the file. Instead, do this :
Server' -> 'Data Import
Dump the data from sql file from here. This worked for me.

Keyboard short for uploading two files in PhpStorm

The problem
In PhpStorm I have a style.css- and a app.js-file that I have to upload to a server over and over again. I'm trying to automate it.
They're compiled by Webpack, so they are generated/compiled. Which means that I can't simply use the 'Tools' >> 'Deployment' >> 'Upload to...' (since that file isn't and won't every be open).
What I currently do
At the moment, every time I want to see the changed I've done, then I do this (for each file):
Navigate to the files in the file-tree (using the mouse)
Select it
The I've set up a shortcut for Main menu >> Tools >> Deployment >> Upload to..., where-after I select the server I want to upload to.
I do this approximately 100+ times per day.
The ideal solution
The ideal solution would be, that if I pressed a shortcut like CMD + Option + Shift + G
That it then uploaded a selection of files (a scope?) to a predefined remote server.
Solution attempts
Open and upload.
Changing to those files (using CMD + p) and then uploading them (once they're open). But the files are generated, which means that it takes PhpStorm a couple of seconds to render the content (which is necessary before I can do anything with the file) - so that's not faster.
Macro.
Recording a macro, uploading the two files, looking like this:
If I go to the menu and trigger the Macro, then it works. So far so good.
But if I assign a shortcut key and trigger that shortcut while in a file, then it shows me this:
And if I press '1' (for it to upload to number 1 on the list), then it uploads the file that I'm currently in(!?), and not the two files from my macro.
I've tried several different shortcuts (to rule out some kind of keyboard-shortcut-clash):
CMD + Option + CTRL + 0
CMD + Shift 0
CMD + ;
... Same result.
And the PhpStorm Macro's doesn't seem to give me that many options anyways.
Keyboard Maestro.
I've tried doing it using Keyboard Maestro.
But I can't get it setup right. Because if it can't find the folders (if they're off-screen or if I'm in a different project and forgot to adjust they shortcuts), then it blasts through the rest of the recorded actions, resulting in chaos. Ideally it should stop, if it can't find the file on the screen.
Update1 - External program
Even if it's not possible to do in PhpStorm, - are there then another program that I could achieve this with?
Update2 - Automatic Deployment in PhpStorm
I've previously used this, - but I've had happen a few times that I started sync'ing waaaay to many files, overwriting critical core files. It seems smart, but can possibly tear down walls if I've forgotten to define an ignore properly.
I wish there was an 'Automatic Deployment for theses files'-function.
Update3 - File Watchers
I looked into file-watchers ( recommendation from #LazyOne ). Based on this forum thread, then file watchers cannot be used to upload files.
It is possible to accomplish it using external program scp (Secure Copy Protocol):
Steps:
1. Create a Scope (for compiled files app.js and style.css)
2. Create a Custom File Watcher with scp over that Scope
Start with Scope:
Create a Local Scope with name scp files for your compiled files directory (I will assume that your webpack compiles into dist directory):
Then, to add dist directory into Scope, select that folder and click on Include Recursively. Apply and Move to File Watchers
Create a custom template for File Watcher:
Choose a Name
Choose File type as Any
Choose Scope as scp files(created earlier)
Choose Program as scp
Choose Arguments as $FileName$ REMOTE_USER#REMOTE_HOST:/REMOTE_DIR_PATH/$FileName$
Choose Working directory as $FileDir$
That's it, basically what we have done is every time when a file in that scope changes, that file is copied with scp to the remote server to the corresponding path.
Voila. Apply Everything and recompile your project and you will see that everything is uploaded to the server.
(I assumed that you have already set up your ssh client; Generated public/private keys; Added a public key in your remote server; And, know ssh credentials to connect to your remote server)
I figured this out myself. I posted the answer here.
The two questions are kind of similar but not identical.
This way I found is also not the best, since it stores the server password in clean text. So I'll leave the question open, in case someone can come up with a better way to achieve this.

View SQL code for job in SQL Server Management Studio

I want to view the SQL code that is executed for a particular job in SQL Server Management Studio.
Specifically, I have a screen that looks like this:
If I double click it I get a screen that looks like this:
That is not really helpful. I want to see the actual code that is running and possibly modify it.
I am a long time developer but new to Windows so please give an answer that uses terminology that I can see on the screen.
[EDIT] If I click the edit button on the first screen I get the same screen as if I double click it. There is a DTSRun command and some jibberish which is not anything I would expect to edit.
[EDIT] I followed these instructions to decode the encrypted command line:
https://blogs.technet.microsoft.com/vipulshah/2007/03/12/how-to-identify-which-dts-package-is-being-called-by-scheduled-job/
Then I could see the command line looks like this:
DTSRun /S "192.168.2.1" /U "sa" /P "changeme" /N "Delete AppErrors"
I then searched the entire computer for a filename that contained AppErrors in the name. I did not find one.
So I am getting closer, but how do I find what that is executing?
There is no SQL code in this job/task, because the task type is "Operating system (CmdExec)", i.e. this is not a SQL query, but starting of Windows executable file. There will be SQL code for step type "Transact-SQL script (T-SQL)":
What you see in you job step, is execution of SSIS package, which is encrypted. For more information about DTSRun command, take a look at this article - SQL Server DTS command line utility.
I almost solved my problem like this:
A.
I followed the instructions here to decode the encrypted command line:
https://blogs.technet.microsoft.com/vipulshah/2007/03/12/how-to-identify-which-dts-package-is-being-called-by-scheduled-job/
Which amounted to:
Copy the DTSRUN line (everything including the DTSRUN)
Open a Windows Command Line window
Paste the DTSRUN line into the CMD window.
To the end of the line, add /!X /!C
/!X = do not execute /!C = copy results onto Windows Clipboard
Run the command
Open Notepad
Click Edit>Paste
that will paste the actual command into Notepad and it will show the name of the package.
B.
I observed that the command line looked like this:
DTSRun /S "192.168.2.1" /U "sa" /P "changeme" /N "Delete AppErrors"
C.
Then I follow the instructions here to find the code:
https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/cc645945(v=sql.105)
which amounted to:
In Object Explorer, expand the Management folder.
Expand the Legacy subfolder.
Expand the Data Transformation Services subfolder to show packages.
D.
I right click on it and choose Open. I get this error:
I should not have to install anything because the person who put this on the machine must have been able to edit it. (this person is completely unavailable so I can't ask him). The reason I need access to it is that we are upgrading the machine.

Restore unsaved MySQL Workbench scripts?

I had a bunch of unsaved scripts open. Today I restarted MySQL Workbench, there was an error message and now the scripts are gone. Is there a way to restore them somehow?
You can try to find your script in History Output. Check this answer: MySql workbench query history ( last executed query / queries ) i.e. create / alter table, select, insert update queries
If the save snapshot option is enable (this can be done by --> Edit>Preferences>SQL Editor>Save snapshot of open editors on close) then you can find the data in \%APPDATA%\MySQL\Workbench\log\sql_actions_unconnected.log. It is a log file, you can copy your code and paste it in a code editor which would put the code in the right format
This just happened to me and thankfully it turns out MySQL Workbench does actually autosave tab contents to disk. You can find them starting at your base configuration file path which is described here. The path to the scratch files is something like this:
{BASE_CONFIG_PATH}/sql_workspaces/{CONNECTION_NAME}.autosave/
Inside that folder is a bunch of .scratch files, looks like one per tab you had open for that connection. They're named with UUIDs, but just drop them all in a text editor and you should be able to find your lost tab contents pretty quickly.
If they're gone, they're gone, unfortunately. You should save them before you exit WorkBench (CTRL+S), since it has been very prone to errors like that, at least to me.

RailsTutorial - Testing - What to put for Database.YML for MySQL?

First, thanks for your help.
As a noob, I've been happily chugging along this well-known tutorial:
http://ruby.railstutorial.org/chapters/static-pages#top
and I'm caught in a section where I enter
rspec spec/
where I receive 2 errors. The 2 errors are in the format of
PagesController GET 'home' should be
successful
Failure/Error: Unable to find matching line from backtrace
Mysql2::Error:Unknown database 'xyz.rb'
where "home" is the name of the action/page. The xyz.rb is the arbitrary
database name I have listed under the test section in database.yml. I
have already raked the database.
I'm pretty sure my problem has to do with how I'm not going with the
sqlite3 in the tutorial but instead with mysql2. The resources I have
managed to find only give guidance on what to input for the development
section in database.yml, but not for the rest of the sections like
"test". So, my question is, what exactly does this error mean, how to
fix it, and how should I configure my database.yml file? I tried
entering a file I see in my db folder like schema.rb, but this renders
the same error.
Thank you very much for your help.
You have two options:
Set up another sqlite database, as is default with a new rails application, or
Create another MySQL database, the same way you set up your development database, with a different name (such as test) and use that for testing.
Here's my database.yml file from the Rails Tutorial that uses SQLite for all the databases; you should be able to copy the test section if you decide to go with #1 above.