linux下mysql的安装以及环境变量的配置
[user@localhost ]$ ls mysql-5.1.51.tar.gz mysql-5.1.51.tar.gz [user@localhost ]$ su 密码: [root@localhost ]# cp mysql-5.1.51.tar.gz /usr/local/src/ [root@localhost ]# cd /usr/local/src/ [root@localhost src]# groupadd -r mysql [root@localh
[user@localhost ]$ ls mysql-5.1.51.tar.gz
mysql-5.1.51.tar.gz
[user@localhost ]$ su
密码:
[root@localhost ]# 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
[root@localhost src]# cd mysql-5.1.51/
[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
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
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/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/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 [失败]
[root@localhost mysql]# /etc/init.d/mysql.server start
Starting MySQL. [确定]
[root@localhost 桌面]# /etc/init.d/mysql.server status
MySQL running (3464) [确定]
[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, 2010, 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
功能说明:设置或显示环境变量
语法:export [-fnp][变量名称]=[变量设置值]
补充说明:在shell中执行程序时,shell会提供一组环境变量。 export可新增,修改或删除环境变量,供后续执行的程序使用。
export的效力仅及于该此登陆操作。
参数:
-f 代表[变量名称]中为函数名称。
-n 删除指定的变量。变量实际上并未删除,只是不会输出到后续指令的执行环境中。
-p 列出所有的shell赋予程序的环境变量。
一个变量创建时,它不会自动地为在它之后创建的shell进程所知。而命令export可以向后面的shell传递变量的值。当一个
shell脚本调用并执行时,它不会自动得到原为脚本(调用者)里定义的变量的访问权,除非这些变量已经被显式地设置为可用。
export命令可以用于传递一个或多个变量的值到任何后继脚本
在Linux 里设置环境变量的方法 ( export PATH )
如果使用源码包安装的软件,在安装完成后一般情况下要设置该软件命令执行的路径,那就是 PATH 变量。如何来设置 PAHT变量呢?我们又三种方法实现
1.直接使用 export 命令 (我们以 mysql 服务举例说明)
[root@ www.linuxidc.com ~]# export PATH=$PATH:/usr/local/mysql/bin
查看是否已经设置好,可以使用命令 export 命令来查看
[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"
需要注意: 直接使用 export 设置的变量都是临时变量,也就是说退出当前的 shell ,为该变量定义的值便不会生效了。如何能让我们定义的变量永久生效呢?那就看我们的第二种定义的方式
2. 修改 /etc/profile
[root@ www.linuxidc.com ~]# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin # 在配置文件中加入此行配置
需要注意的是:修改完这个文件必须要使用 以下命令在不用重启系统的情况下使修改的内容生效
[root@ www.linuxidc.com ~]# source /etc/profile
或者是:
[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
# 配置已经生效
3. 修改 .bashrc 文件是在当前用户 shell 下生效
# vi /root/.bashrc
在里面加入:
export PATH=$PATH:/usr/local/mysql/bin
修改这个文件之后同样也需要使用 source 或者是 . 使配置文件生效。
再来使用 echo $PATH看下变量是否生效
[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”等路径已经在系统环境变量中了,如果可执行文件在这几个标准位置,在终端命令行输入该软件可执行文件的文件名和参数(如果需要参数),回车即可。
如果不在标准位置,文件名前面需要加上完整的路径。不过每次都这样跑就太麻烦了,一个“一劳永逸”的办法是把这个路径加入环境变量。命令 “PATH=$PATH:路径”可以把这个路径加入环境变量,但是退出这个命令行就失效了。要想永久生效,需要把这行添加到环境变量文件里。有两个文件可选:“/etc/profile”和用户主目录下的“.bash_profile”,“/etc/profile”对系统里所有用户都有效,用户主目录下的“.bash_profile”只对这个用户有效。
“PATH=$PATH:路径1:路径2:...:路径n”,意思是可执行文件的路径包括原先设定的路径,也包括从“路径1”到“路径n”的所有路径。当用户输入一个一串字符并按回车后,shell会依次在这些路径里找对应的可执行文件并交给系统核心执行。那个“$PATH”表示原先设定的路径仍然有效,注意不要漏掉。某些软件可能还有“PATH”以外类型的环境变量需要添加,但方法与此相同,并且也需要注意“$”。
注意,与DOS/Window不同,UNIX类系统环境变量中路径名用冒号分隔,不是分号。另外,软件越装越多,环境变量越添越多,为了避免造成混乱,建议所有语句都添加在文件结尾,按软件的安装顺序添加。
格式如下():
# 软件名-版本号
PATH=$PATH:路径1:路径 2:...:路径n
其他环境变量=$其他环境变量:...
在“profile”和“.bash_profile”中,“#”是注释符号,写在 这里除了视觉分隔外没有任何效果。
设置完毕,注销并重新登录,设置就生效了。如果不注销,直接在shell里执行这些语句,也能生效,但是作用范围只限于执行了这些语句的shell。
相关的环境变量生效后,就不必老跑到软件的可执行文件目录里去操作了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Docker is important on Linux because Linux is its native platform that provides rich tools and community support. 1. Install Docker: Use sudoapt-getupdate and sudoapt-getinstalldocker-cedocker-ce-clicotainerd.io. 2. Create and manage containers: Use dockerrun commands, such as dockerrun-d--namemynginx-p80:80nginx. 3. Write Dockerfile: Optimize the image size and use multi-stage construction. 4. Optimization and debugging: Use dockerlogs and dockerex

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

CentOS is the first choice for server and enterprise environments for its superior security, stability and performance. 1) Security provides forced access control through SELinux to improve system security. 2) Stability is supported by the LTS version for up to 10 years to ensure the stability of the system. 3) Performance significantly improves system response speed and resource utilization by optimizing kernel and system configuration.
