Command to start mysql server in linux

How do you start a MySQL server on linux?

Pretty simple question here. I just want a SQL database on my version of Kali linux so I can practice SQL.

I opened the command line and entered tried to start mysql and get an error.

I also made sure it was already installed using apt-get.

What are the steps I need to take to be able to make a database with tables and data that I can query?

2 Answers 2

I don’t know about Kali, but on Ubuntu it would be

Once that command returns, the mysqld service has started, so you can use the mysql client to connect to it.

Of course, you also have to make sure you have the mysql-server package installed, not just mysql-client and mysql-common , and that you’ve initialized the database instance. Complete post-installation instructions can be found in the official documentation, but the short version is

  1. Make sure the installer has created the mysql user account. This is the account that will «own» the server process once it starts.
  2. Change to your data directory. (I used the installer’s default of /var/lib/mysql ; you can change this by editing my.cnf .)

As root, execute the server daemon with the —initialize switch. Check whereis to determine the correct path, then

This command will twiddle itself for a while, then display an automatically-generated password and exit. Once the command returns, the database instance has been initialized and the system tables created. You can now start the database instance normally (using service start ), then log in as the database user root (which is not the same as the system user root ) using the password from above, then change your password, create a new database user, log in as that user, create a user database, and start creating tables.

Again, the official documentation is the place to look for this; if any of the instructions in the official documentation differ from my instructions, you should ignore me and follow the official documentation’s instructions.

Источник

Command to start mysql server in linux

MySQL distributions on Unix and Unix-like system include a script named mysql.server , which starts the MySQL server using mysqld_safe . It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services. It is also used by the macOS Startup Item for MySQL.

mysql.server is the script name as used within the MySQL source tree. The installed name might be different (for example, mysqld or mysql ). In the following discussion, adjust the name mysql.server as appropriate for your system.

For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, mysql.server and mysqld_safe are not installed because they are unnecessary. For more information, see Managing MySQL Server with systemd.

To start or stop the server manually using the mysql.server script, invoke it from the command line with start or stop arguments:

mysql.server changes location to the MySQL installation directory, then invokes mysqld_safe . To run the server as some specific user, add an appropriate user option to the [mysqld] group of the global /etc/my.cnf option file, as shown later in this section. (It is possible that you must edit mysql.server if you’ve installed a binary distribution of MySQL in a nonstandard location. Modify it to change location into the proper directory before it runs mysqld_safe . If you do this, your modified version of mysql.server may be overwritten if you upgrade MySQL in the future; make a copy of your edited version that you can reinstall.)

mysql.server stop stops the server by sending a signal to it. You can also stop the server manually by executing mysqladmin shutdown .

To start and stop MySQL automatically on your server, you must add start and stop commands to the appropriate places in your /etc/rc* files:

If you use the Linux server RPM package ( MySQL-server- VERSION .rpm ), or a native Linux package installation, the mysql.server script may be installed in the /etc/init.d directory with the name mysqld or mysql . See Installing MySQL on Linux Using RPM Packages from Oracle, for more information on the Linux RPM packages.

If you install MySQL from a source distribution or using a binary distribution format that does not install mysql.server automatically, you can install the script manually. It can be found in the support-files directory under the MySQL installation directory or in a MySQL source tree. Copy the script to the /etc/init.d directory with the name mysql and make it executable:

After installing the script, the commands needed to activate it to run at system startup depend on your operating system. On Linux, you can use chkconfig :

On some Linux systems, the following command also seems to be necessary to fully enable the mysql script:

On FreeBSD, startup scripts generally should go in /usr/local/etc/rc.d/ . Install the mysql.server script as /usr/local/etc/rc.d/mysql.server.sh to enable automatic startup. The rc(8) manual page states that scripts in this directory are executed only if their base name matches the *.sh shell file name pattern. Any other files or directories present within the directory are silently ignored.

As an alternative to the preceding setup, some operating systems also use /etc/rc.local or /etc/init.d/boot.local to start additional services on startup. To start up MySQL using this method, append a command like the one following to the appropriate startup file:

For other systems, consult your operating system documentation to see how to install startup scripts.

mysql.server reads options from the [mysql.server] and [mysqld] sections of option files. For backward compatibility, it also reads [mysql_server] sections, but to be current you should rename such sections to [mysql.server] .

You can add options for mysql.server in a global /etc/my.cnf file. A typical my.cnf file might look like this:

The mysql.server script supports the options shown in the following table. If specified, they must be placed in an option file, not on the command line. mysql.server supports only start and stop as command-line arguments.

Table 4.2 mysql.server Option-File Options

Option Name Description Type
basedir Path to MySQL installation directory Directory name
datadir Path to MySQL data directory Directory name
pid-file File in which server should write its process ID File name
service-startup-timeout How long to wait for server startup Integer

The path to the MySQL installation directory.

The path to the MySQL data directory.

The path name of the file in which the server should write its process ID. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.

Источник

Command to start mysql server in linux

MySQL distributions on Unix and Unix-like system include a script named mysql.server , which starts the MySQL server using mysqld_safe . It can be used on systems such as Linux and Solaris that use System V-style run directories to start and stop system services. It is also used by the macOS Startup Item for MySQL.

mysql.server is the script name as used within the MySQL source tree. The installed name might be different (for example, mysqld or mysql ). In the following discussion, adjust the name mysql.server as appropriate for your system.

For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, mysql.server and mysqld_safe are not installed because they are unnecessary. For more information, see Section 2.5.9, “Managing MySQL Server with systemd”.

To start or stop the server manually using the mysql.server script, invoke it from the command line with start or stop arguments:

mysql.server changes location to the MySQL installation directory, then invokes mysqld_safe . To run the server as some specific user, add an appropriate user option to the [mysqld] group of the global /etc/my.cnf option file, as shown later in this section. (It is possible that you must edit mysql.server if you’ve installed a binary distribution of MySQL in a nonstandard location. Modify it to change location into the proper directory before it runs mysqld_safe . If you do this, your modified version of mysql.server may be overwritten if you upgrade MySQL in the future; make a copy of your edited version that you can reinstall.)

mysql.server stop stops the server by sending a signal to it. You can also stop the server manually by executing mysqladmin shutdown .

To start and stop MySQL automatically on your server, you must add start and stop commands to the appropriate places in your /etc/rc* files:

If you use the Linux server RPM package ( MySQL-server- VERSION .rpm ), or a native Linux package installation, the mysql.server script may be installed in the /etc/init.d directory with the name mysqld or mysql . See Section 2.5.4, “Installing MySQL on Linux Using RPM Packages from Oracle”, for more information on the Linux RPM packages.

If you install MySQL from a source distribution or using a binary distribution format that does not install mysql.server automatically, you can install the script manually. It can be found in the support-files directory under the MySQL installation directory or in a MySQL source tree. Copy the script to the /etc/init.d directory with the name mysql and make it executable:

After installing the script, the commands needed to activate it to run at system startup depend on your operating system. On Linux, you can use chkconfig :

On some Linux systems, the following command also seems to be necessary to fully enable the mysql script:

On FreeBSD, startup scripts generally should go in /usr/local/etc/rc.d/ . Install the mysql.server script as /usr/local/etc/rc.d/mysql.server.sh to enable automatic startup. The rc(8) manual page states that scripts in this directory are executed only if their base name matches the *.sh shell file name pattern. Any other files or directories present within the directory are silently ignored.

As an alternative to the preceding setup, some operating systems also use /etc/rc.local or /etc/init.d/boot.local to start additional services on startup. To start up MySQL using this method, append a command like the one following to the appropriate startup file:

For other systems, consult your operating system documentation to see how to install startup scripts.

mysql.server reads options from the [mysql.server] and [mysqld] sections of option files. For backward compatibility, it also reads [mysql_server] sections, but to be current you should rename such sections to [mysql.server] .

You can add options for mysql.server in a global /etc/my.cnf file. A typical my.cnf file might look like this:

The mysql.server script supports the options shown in the following table. If specified, they must be placed in an option file, not on the command line. mysql.server supports only start and stop as command-line arguments.

Table 4.7 mysql.server Option-File Options

Option Name Description Type
basedir Path to MySQL installation directory Directory name
datadir Path to MySQL data directory Directory name
pid-file File in which server should write its process ID File name
service-startup-timeout How long to wait for server startup Integer

The path to the MySQL installation directory.

The path to the MySQL data directory.

The path name of the file in which the server should write its process ID. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.

Источник

Command to start mysql server in linux

This section describes how start the server on Unix and Unix-like systems. (For Windows, see Section 2.3.4.5, “Starting the Server for the First Time”.) For some suggested commands that you can use to test whether the server is accessible and working properly, see Section 2.10.3, “Testing the Server”.

Start the MySQL server like this if your installation includes mysqld_safe :

For Linux systems on which MySQL is installed using RPM packages, server startup and shutdown is managed using systemd rather than mysqld_safe , and mysqld_safe is not installed. See Section 2.5.10, “Managing MySQL Server with systemd”.

Start the server like this if your installation includes systemd support:

Substitute the appropriate service name if it differs from mysqld (for example, mysql on SLES systems).

It is important that the MySQL server be run using an unprivileged (non- root ) login account. To ensure this, run mysqld_safe as root and include the —user option as shown. Otherwise, you should execute the program while logged in as mysql , in which case you can omit the —user option from the command.

For further instructions for running MySQL as an unprivileged user, see Section 6.1.5, “How to Run MySQL as a Normal User”.

If the command fails immediately and prints mysqld ended , look for information in the error log (which by default is the host_name .err file in the data directory).

If the server is unable to access the data directory it starts or read the grant tables in the mysql database, it writes a message to its error log. Such problems can occur if you neglected to create the grant tables by initializing the data directory before proceeding to this step, or if you ran the command that initializes the data directory without the —user option. Remove the data directory and run the command with the —user option.

Источник

Читайте также:  Windows шифрование папки паролем
Оцените статью