One place for hosting & domains


      Connect to a MySQL Database Using the mysql Command

      , by Linode

      Traducciones al Español

      Estamos traduciendo nuestros guías y tutoriales al Español. Es
      posible que usted esté viendo una traducción generada
      automáticamente. Estamos trabajando con traductores profesionales
      para verificar las traducciones de nuestro sitio web. Este proyecto
      es un trabajo en curso.

      Create a Linode account
      to try this guide with a $100 credit.

      This credit will be applied to any valid services used during your first 60 days.

      This guide shows you how to connect to a MySQL database using
      mysql, the MySQL command-line client. This opens up a simple SQL shell environment, allowing you to perform
      SQL queries and commands on your database. If you require more advanced capabilities, consider using the
      MySQL Shell.


      If you wish to connect to a Linode MySQL Managed Database, review the
      Connect to a MySQL Managed Database guide instead.

      Before You Begin

      • Obtain the connection details for the MySQL instance you wish to use. If you do not have a MySQL instance yet, you can
        create a Managed Database,
        deploy the MySQL Marketplace App, or
        install MySQL server (or MariaDB) on a Compute Instance. This instance must allow remote connections or you must run the mysql command from within same system.

      • Ensure mysql is installed and is compatible with the MySQL version on your database server. Run the following command on the system you intend on using to verify that mysql is installed.

        mysql --version

        This should inform you which version you are using. If the command is not found or you are not on a compatible version, see the
        Installing MySQL guide.


      The steps in this guide are written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, see the
      Linux Users and Groups guide.

      General mysql Syntax

      The main purpose of the mysql utility is to connect to a MySQL database server and open a simple SQL shell environment. The mysql command can be used to connect to either a local or remote database server. In the commands provided below, see the
      Common Command Options for information on each of the available options.

      • Local database server: Use this command when connecting to a MySQL Server instance running on the same machine you are using.

        mysql -u [username] -p
      • Remote database server: In many cases, the database server is not on the same system you are using. In these cases, you can SSH in to the remote system (if permitted) and run the command above to connect to a local MySQL instance. Alternatively, you can use the mysql command to remotely connect to the database. If your MySQL server does not allow remote connections or your user cannot connect remotely, see
        Configure the Database Server to Allow Remote Connections.

        mysql -h [host] -p [port] -u [username] -p


        If you wish to connect to a Linode MySQL Managed Database, review the
        Connect to a MySQL Managed Database guide instead.

      Common Command Options

      The following list is a collection of common options used with the mysqldump command. At minimum, the username and password is required. When connecting to a remote database server, the host (and perhaps the port) should be provided. For a full list of available options, reference the
      Command Options for Connecting to the Server documentation.

      • Username (--user=[] or -u []): The username of your MySQL user. This user must have proper grants to access the database.

      • Password (--password=[] or -p[]): Specifies that the user’s password is required for the connection. The password can be entered directly in the command itself (though that is not recommended due to security concerns) or the password can be omitted (by just using the --password option with no value). In the password is omitted, mysql prompts you for the password before connecting to the database. For more details about password security, see MySQL’s
        End-User Guidelines for Password Security.

      • Host (--host=[] or -h []): The IP address or FQDN (fully qualified domain name) of the remote database server. You can omit this option from the command if you are connecting to a local MySQL instance on your same system.

      • Port (--port=[] or -P []): The port number of that the MySQL database instance uses. This can be omitted if your MySQL instance uses the default port of 3306.

      • SSL Settings (--ssl-mode): This controls if the connection should be encrypted. This can be set to DISABLED (unencrypted – not recommended), PREFERRED (tries an encrypted connection first before falling back to unencrypted), or REQUIRED (fails if an encrypted connection can’t be established. If omitted, this option is automatically set to PREFERRED. You can also set this to VERIFY_CA or VERIFY_IDENTITY to require an encrypted connection and either verify the CA certificate or both verify the CA certificate and the host name identity.

      If you are frequently connecting to the same database, you can securely store many of these options (including the password). See the
      Securely Storing Credentials guide. Other options can be stored in an
      option file.

      Configure the Database Server to Allow Remote Connections

      If you have installed the MySQL server yourself (not through a managed service) and wish to connect to a database remotely without first logging in to the database server through SSH, you may need to modify a few settings. This can be useful if you want to limit SSH access but still permit database access.

      Refer to our
      Create an SSH Tunnel for MySQL Remote Access to learn how to connect to your database using an SSH tunnel.

      1. Make sure your database has a user set up to allow connections from your local machine’s IP address.

        The example below displays a series of commands to create a new MySQL/MariaDB user named example_user. The user accepts connections from and has SELECT, INSERT, UPDATE, and DELETE permissions on the example_db database:

        CREATE user 'example_user'@'' IDENTIFIED BY 'password';
        GRANT SELECT,INSERT,UPDATE,DELETE ON example-db.* TO 'example_user' IDENTIFIED BY 'password';
      2. Locate you database’s configuration files using the command below. The following command lists the files’ default locations. The locations returned by the command may be different than those in the example shown below:

        sudo mysql --help
        Default options are read from the following files in the given order:
        /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
      3. Using your preferred text editor, locate the [mysqld] section and a bind-address parameter.

        If you see any !includedir parameters in the files, you may also need to check the files in the locations those parameters designate.

      4. Once you locate the bind-address parameter, change it from the default to This enables external connections on the database.

        Also, if the file contains a skip-networking parameter, comment it out with a #.

        File: /etc/mysql/mysql.conf.d/mysqld.conf
        # skip-networking
        bind-address =
      5. Restart the MySQL service.

        sudo systemctl restart mysqld

      Follow our
      Install MySQL Workbench for Database Administration guide for steps to install the MySQL Workbench tool on your local machine. This guide also shows you how to connect to a remote database via MySQL Workbench. These steps work whether your target database server is MySQL or MariaDB.

      For more information, take a look at the
      official MySQL Workbench manual. You may also refer to MariaDB’s documentation on
      using the MySQL Workbench with MariaDB.


      Now that you have your remote database connection, you may want to learn more about using MySQL/MariaDB and working with more advanced database operations. You can refer to our extensive
      list of MySQL guides and specific
      MariaDB guides to build your database management skills.

      More Information

      You may wish to consult the following resources for additional information
      on this topic. While these are provided in the hope that they will be
      useful, please note that we cannot vouch for the accuracy or timeliness of
      externally hosted materials.

      This page was originally published on

      Join the conversation.
      Read other comments or post your own below. Comments must be respectful,
      constructive, and relevant to the topic of the guide. Do not post external
      links or advertisements. Before posting, consider if your comment would be
      better addressed by contacting our
      Support team or asking on
      Community Site.

      Source link

      How To Install and Use the Visual Studio Code (VS Code) Command Line Interface


      Visual Studio Code is a free, open-source, and cross-platform text editor developed primarily by Microsoft. It uses web technologies such as JavaScript and CSS, which has helped facilitate a large ecosystem of community-created plugins to extend its functionality into many different programming languages and features.

      In this tutorial, you’ll install the Visual Studio Code command line interface and learn how to use it to open files and directories, compare changes between files, and install extensions.


      To complete this tutorial, you’ll need to have Visual Studio Code installed. Please refer to the official Setting up Visual Studio Code documentation to find out how to install Code for your platform.

      Installing the Visual Studio Code Command Line Interface

      You may need to install the Visual Studio Code command line interface before using it. To do so, first launch the normal Visual Studio Code graphical interface. If this is your first time opening the app, the default screen will have a icon bar along the left, and a default welcome tab:

      A screenshot of the default

      Visual Studio Code provides a built-in command to install its command line interface. Bring up Code’s Command Palette by typing Command+Shift+P on Mac, or Control+Shift+P on Windows and Linux:

      A screenshot of the Visual Studio Code interface with the Command Palette activated, waiting for input to be entered after its '>' prompt

      This will open a prompt near the top of your Code window. Type shell command into the prompt. It should autocomplete to the correct command which will read Shell Command: Install 'code' command in PATH:

      A screenshot of the Visual Studio Code interface, with the Command Palette activated and the "Install 'code' command in PATH" command highlighted

      Press ENTER to run the highlighted command. You may be prompted to enter your administrator credentials to finish the installation process.

      You now have the code command line command installed.

      Verify that the install was successful by running code with the --version flag:


      1.62.1 f4af3cbf5a99787542e2a30fe1fd37cd644cc31f x64

      If your output includes a version string, you’ve successfully installed the Visual Studio Code command line interface. The next few sections will show you a few ways to use it.

      Opening Files with the code Command

      Running the code command with one or more filenames will open those files in the Visual Studio Code GUI:

      This will open the file1 file in Code.

      This will open all markdown (.md) files in the current directory in Code.

      By default, the files will be opened in an existing Code window if one is available. Use the --new-window flag to force Visual Studio Code to open a new window for the specified files.

      Opening a Directory with the code Command

      Use the code command followed by one or more directory names to open the directories in a new Visual Studio Code window:

      • code directory1 directory2

      Code will open a new window for the directories. Use the --reuse-window flag to tell Code to reuse the existing frontmost window instead.

      Opening a .code-workspace Workspace File with the code Command

      Opening a workspace file with the code command works similar to opening directories:

      • code example.code-workspace

      This will open the example workspace in a new window, unless you reuse an existing window by adding the --reuse-window flag.

      Installing an Extension Using the code Command

      You can install Visual Studio Code extensions using the code command line tool as well. To do so, you’ll first need to know the extension’s unique identifier. To find this information, first navigate to the extension’s page on the Visual Studio Marketplace.

      For instance, here is the page for the Jupyter Notebook extension:

      Notice the itemName parameter in the address. This parameter’s value, ms-toolsai.jupyter, is this extension’s unique identifier.

      You can also find this information on the Marketplace page itself, towards the bottom of the right-hand column in the More info section:

      A screenshot of the Jupyter extension's page on the Visual Studio Marketplace, highlighting the 'Unique Identifier ms-toosai.jupyter' unique id information in the page's right-hand column

      Once you have this unique id, you can use it with code --install-extension to install the extension:

      • code --install-extension ms-toolsai.jupyter


      Installing extension 'ms-toolsai.jupyter'... Extension 'ms-toolsai.jupyter' v2021.11.1001489384 was successfully installed.

      Use the same id with the --uninstall-extension flag to uninstall the extension.

      Showing the Differences Between Two Files Using the code Command

      To show a standard split-screen diff that will highlight the additions, deletions, and changes between two files, use the --diff flag:

      A screenshot of the Visual Studio Code diff interface, with two files side by side, and the second line highlighted, showing a few words have changed between the two versions

      Similar to opening files, this will reuse the frontmost window by default, if one exists. To force a new window to open, use the --new-window flag.

      Piping stdin Into Visual Studio Code Using the code Command

      An important feature of most command line shells is the ability to pipe (or send) the output of one command to the input of the next. In the following command line, notice the | pipe character connecting the ls ~ command to code -:

      This will execute the ls command on the ~ directory, which is a shortcut for the current user’s home directory. The output from ls will be a list of files and directories in your home directory. This will be sent to the code command, where the single - indicates that it should read the piped in text instead of a file.

      code will output some information about the temporary file that it has created to hold the input:


      Reading from stdin via: /var/folders/dw/ncv0fr3x0xg7tg0c_cvfynvh0000gn/T/code-stdin-jfa

      Then this file will open up in the Code GUI interface:

      A screenshot of Visual Studio Code with a text file open, displaying the text piped in from the ls command. The text is standard directories such as Desktop and Documents, along with file1 and file2 used in the previous section

      This command will continue to wait indefinitely for more input. Press CTRL+C to have code stop listening and return you to your shell.

      Add the --new-window flag to force Code to open a new window for the input.


      In this tutorial you installed Visual Studio Code’s code command line tool, and used it to open files and directories, compare files, and install extensions.

      To learn more about the code command, you can run its --help function:

      You can also refer to the official Visual Studio Code command line documentation or take a look at our VS Code tag page for more Visual Studio Code tutorials, tech talks, and Q&A.

      Source link

      Build Your First Command Line Tool in Go

      How to Join

      This Tech Talk is free and open to everyone. Register below to get a link to join the live stream or receive the video recording after it airs.

      Date Time RSVP
      October 27, 2021 11:00 a.m.–12:00 p.m. ET / 3:00–4:00 p.m. GMT

      About the Talk

      Command line tools are amazing. They are simple, easy to automate, and fun to build. In this Tech Talk, we’ll build a simple command line tool that helps us run our D&D campaign, package it up, and set up GitHub actions to build our tool.

      What You’ll Learn

      • How to build a command line tool in go
      • How to package your command line tool and upload it to GitHub releases

      This Talk Is Designed For

      Any developer who wants to build a command line application


      A basic understanding of Golang and how to setup a Golang environment


      Golang documentation
      Getting started on DigitalOcean

      Source link