Install MySQL and configure environment variables in Linux

Source: Internet
Author: User
Tags localhost mysql

[User @ localhost] $ ls mysql-5.1.51.tar.gz

Mysql-5.1.51.tar.gz

[User @ localhost] $ su

Password:

# Cp mysql-5.1.51.tar.gz/usr/local/src/

[Root @ localhost] # cd/usr/local/src/

[Root @ localhost SRC] # groupadd-r MySQL

[Root @ localhost SRC] # useradd-G mysql-r MySQL

[Root @ localhost SRC] # gunzip <mysql-5.1.51.tar.gz | tar-xvf-

[Root @ localhost SRC] # mysql-5.1.51/CD/

[Root @ localhost mysql-5.1.51] #./configure-Prefix =/usr/local/MySQL/

[Root @ localhost mysql-5.1.51] # Make

[Root @ localhost mysql-5.1.51] # make install

[Root @ localhost mysql-5.1.51] # cd/usr/local/MySQL/

[Root @ localhost MySQL] # chown-r MySQL.

[Root @ localhost MySQL] # chgrp-r MySQL.

[Root @ localhost MySQL] #/usr/local/MySQL/bin/mysql_install_db -- user = MySQL

Installing MySQL system tables...

OK

Filling help tables...

OK

 

To start mysqld at boot time you have to copy

Support-files/MySQL. Server to the right place for your system

 

Please remember to set a password for the MySQL Root User!

To do so, start the server, then issue the following commands:

 

/Usr/local/MySQL/bin/mysqladmin-u Root Password 'new-password'

/Usr/local/MySQL/bin/mysqladmin-u root-H localhost. localdomain password 'new-password'

 

Alternatively you can run:

/Usr/local/MySQL/bin/mysql_secure_installation

 

Which will also give you the option of removing the test

Databases and anonymous user created by default. This is

Stronugly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon:

CD/usr/local/MySQL;/usr/local/MySQL/bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

CD/usr/local/MySQL-test; Perl mysql-test-run.pl

 

Please report any problems with the/usr/local/MySQL/bin/mysqlbug script!

 

[Root @ localhost MySQL] # chown-r root.

[Root @ localhost MySQL] # chown-r MySQL/usr/local/MySQL/var/

[Root @ localhost MySQL] # cp/usr/local/MySQL/share/MySQL/my-huge.cnf/etc/My. CNF

[Root @ localhost MySQL] # cp/usr/local/MySQL/share/MySQL. Server/etc/init. d/MySQL. Server

[Root @ localhost MySQL] #/usr/local/MySQL/bin/MySQL-V

/Usr/local/MySQL/bin/MySQL ver 14.14 distrib 5.1.51, for PC-Linux-GNU (i686) using editline wrapper

[Root @ localhost MySQL] #/etc/init. d/MySQL. Server Status

MySQL is not running [failed]

[Root @ localhost MySQL] #/etc/init. d/MySQL. Server start

Starting mysql. [OK]

[Root @ localhost desktop] #/etc/init. d/MySQL. Server Status

MySQL running (3464) [OK]

[Root @ localhost MySQL] #/usr/local/MySQL/bin/MySQL

Welcome to the MySQL monitor. commands end with; or \ G.

Your MySQL connection ID is 1

Server version: 5.1.51-log Source Distribution

 

Copyright (c) 2000,201 0, Oracle and/or its affiliates. All rights reserved.

This software comes with absolutely no warranty. This is free software,

And you are welcome to modify and redistribute it under the GPL V2 license

 

Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.

 

Mysql> exit

Bye

 

Function Description: sets or displays environment variables.

Syntax: Export [-FNP] [variable name] = [variable setting value]

Note: When executing a program in shell, shell provides a set of environment variables. Export allows you to add, modify, or delete environment variables for subsequent programs.

The effect of export is only true for this login operation.

Parameters:

-F indicates the function name in [variable name.

-N: Delete the specified variable. The variable is not actually deleted, but is not output to the execution environment of subsequent commands.

-P: list all environment variables that the shell assigns to the program.

When a variable is created, it is not automatically known to the shell process created after it. The command export can pass the variable value to the shell in the back. When

When a shell script is called and executed, it does not automatically obtain access to the variables defined in the original script (caller) unless these variables have been explicitly set to available.

The Export command can be used to pass the value of one or more variables to any subsequent script.

How to Set environment variables in Linux (export path)

If you use the software installed in the source code package, you must set the path for executing the software command after the installation is complete, that is, the PATH variable. How can I set the paht variable? Three more methods are available.

1. Use the Export command directly (for example, MySQL Service)

[Root @ www.linuxidc.com ~] # Export Path = $ path:/usr/local/MySQL/bin

Run the Export command to check whether the settings have been set.

[Root @ www.linuxidc.com ~] # Export

Declare-x cvs_rsh = "ssh"

Declare-x g_broken_filenames = "1"

Declare-x histsize = "1000"

Declare-x home = "/root"

Declare-x hostname = "www.linuxidc.com"

Declare-x inputrc = "/etc/inputrc"

Declare-x lang = "en_US.UTF-8"

Declare-x lessopen = "|/usr/bin/lesspipe. sh % s"

Declare-x LOGNAME = "root"

Declare-x ls_colors = "NO = 00: fi = 00: di = 01; 34: Ln = 01; 36: Pi = 40; 33: So = 01; 35: BD = 40; 33; 01: Cd = 40; 33; 01: OR = 01; 05; 37; 41: MI = 01; 05; 37; 41: Ex = 01; 32 :*. cmd = 01; 32 :*. EXE = 01; 32 :*. COM = 01; 32 :*. BTM = 01; 32 :*. bat = 01; 32 :*. SH = 01; 32 :*. CSH = 01; 32 :*. tar = 01; 31 :*. tgz = 01; 31 :*. ARJ = 01; 31 :*. taz = 01; 31 :*. lzh = 01; 31 :*. zip = 01; 31 :*. z = 01; 31 :*. z = 01; 31 :*. gz = 01; 31 :*. bz2 = 01; 31 :*. bz = 01; 31 :*. TZ = 01; 31 :*. rpm = 01; 31 :*. cpio = 01; 31 :*. JPG = 01; 35 :*. GIF = 01; 35 :*. BMP = 01; 35 :*. xbm = 01; 35 :*. XPM = 01; 35 :*. PNG = 01; 35 :*. TIF = 01; 35 :"

Declare-x mail = "/var/spool/mail/root"

Declare-x oldpwd

Declare-x Path = "/usr/Kerberos/sbin:/usr/Kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin: /usr/sbin:/usr/bin:/root/bin:/usr/local/MySQL/bin"

Declare-x Pwd = "/root"

Declare-x shell = "/bin/bash"

Declare-x shlvl = "1"

Declare-x ssh_askpass = "/usr/libexec/OpenSSH/gnome-ssh-askpass"

Declare-x ssh_auth_sock = "/tmp/ssh-AbUtqs3354/agent.3354"

Declare-x ssh_client = "192.168.1.102 2640 22"

Declare-x ssh_connection = "192.168.1.102 2640 192.168.1.110 22"

Declare-x ssh_tty = "/dev/pts/0"

Declare-x term = "VT100"

Declare-x user = "root"

Note: The variables directly set by using export are temporary variables. That is to say, exit the current shell and the value defined for this variable will not take effect. How can we make the Defined variables take effect permanently? Let's look at our second method of definition.

2. Modify/etc/profile

[Root @ www.linuxidc.com ~] # Vi/etc/profile

Export Path = $ path:/usr/local/MySQL/bin # Add this row configuration in the configuration file

Note: After modifying this file, you must use the following command to make the modification effective without restarting the system.

[Root @ www.linuxidc.com ~] # Source/etc/profile

Or:

[Root @ www.linuxidc.com ~] #./Etc/profile

[Root @ www.linuxidc.com ~] # Echo $ path

/Usr/Kerberos/sbin:/usr/Kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin: /usr/bin:/root/bin:/usr/local/MySQL/bin

# The configuration has taken effect.

3. Modify the. bashrc file to take effect under the current User Shell

# Vi/root/. bashrc
Add:

Export Path = $ path:/usr/local/MySQL/bin

After modifying this file, you also need to use source or. To make the configuration file take effect.

Use echo $ path to check whether the variable takes effect.

[Root @ www.linuxidc.com ~] # Echo $ path

/Usr/Kerberos/sbin:/usr/Kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin: /usr/bin:/root/bin:/usr/local/MySQL/bin

######################################## #######

"/Bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/local/bin", and other paths are already in the system environment variables. now, if the executable file is in these standard locations, enter the file name and parameters of the executable file of the software in the terminal command line (if you need parameters), press Enter.

If it is not in the standard position, you must add the complete path before the file name. However, it is too troublesome to run like this every time. A "once and for all" method is to add this path to the environment variable. The command "Path = $ path: path" can add this path to the environment variable, but exit this command line will become invalid. To take effect permanently, add this line to the environment variable file. Two files are available: "/etc/profile" and ". bash_profile "and"/etc/profile "are valid for all users in the system. bash_profile "is only valid for this user.

"Path = $ path: Path 1: Path 2 :...: path N, which indicates that the path of the executable file includes the original path, and all paths from "Path 1" to "path N. After you enter a string of characters and press enter, shell finds the corresponding executable files in these paths and submits them to the system core for execution. The "$ path" indicates that the previously set path is still valid. Do not miss it. Some software may have environment variables other than "path" that need to be added, but the method is the same, and you also need to pay attention to "$ ".

Note: Unlike DOS/window, path names in Unix-type system environment variables are separated by colons instead of semicolons. In addition, the more software is installed, the more environment variables are added. To avoid confusion, we recommend that you add all statements at the end of the file and add them in the software installation order.

The format is as follows ():

# Software name-version number

Path = $ path: Path 1: Path 2:...: path n

Other environment variables = $ other environment variables :...

In "Profile" and ". bash_profile", "#" is a annotator, which has no effect except visual separation.

After setting, log out and log on again. The setting takes effect. If you do not deregister a statement, it can take effect if you execute these statements directly in the shell, but the scope is limited to the shell that executes these statements.

After the related environment variables take effect, you do not have to go to the executable file directory of the software to perform operations.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.