MYSQL简单安装配置

有用的URL:

http://www.cnblogs.com/zeroone/articles/2298942.html

http://blog.csdn.net/h1017597898/article/details/9815987

 

 

安装之后,新建用户及密码,新建数据库,分配权限

mysql> CREATE USER 'user'@'%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> create database DB;
Query OK, 1 row affected (0.00 sec)

mysql>create database DB default character set utf8 collate utf8_general_ci; (为了DJANGO操作中文不乱码) 
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL ON DB.* TO 'user'@'%'; 

Query OK, 0 rows affected (0.00 sec) 

mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)

YUM安装的MYSQL之后,第一次启动时的安全配置:

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h cnsz141539 password 'new-password'

Alternatively you can run:
/usr/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 ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

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

如果要将MYSQL放入SERVICE服务,相应的脚本为:

#!/bin/sh
#
# mysqld    This shell script takes care of starting and stopping
#        the MySQL subsystem (mysqld).
#
# chkconfig: - 64 36
# description:    MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile: /var/run/mysqld/mysqld.pid
### BEGIN INIT INFO
# Provides: mysqld
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
# Required-Stop: $local_fs $remote_fs $network $named $syslog $time
# Short-Description: start and stop MySQL server
# Description: MySQL database server
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

exec="/usr/bin/mysqld_safe"
prog="mysqld"

# Set timeouts here so they can be overridden from /etc/sysconfig/mysqld
STARTTIMEOUT=120
STOPTIMEOUT=60

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
    result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
    if [ -z "$result" ]; then
        # not found, use default
        result="$3"
    fi
}

get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
errlogfile="$result"
get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
mypidfile="$result"

start(){
    [ -x $exec ] || exit 5
    # check to see if it's already running
    MYSQLDRUNNING=0
    if [ -f "$mypidfile" ]; then
    MYSQLPID=`cat "$mypidfile" 2>/dev/null`
    if [ -n "$MYSQLPID" ] && [ -d "/proc/$MYSQLPID" ] ; then
        MYSQLDRUNNING=1
    fi
    fi
    RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
    if [ $MYSQLDRUNNING = 1 ] && [ $? = 0 ]; then
    # already running, do nothing
    action $"Starting $prog: " /bin/true
    ret=0
    elif [ $MYSQLDRUNNING = 1 ] && echo "$RESPONSE" | grep -q "Access denied for user"
    then
    # already running, do nothing
    action $"Starting $prog: " /bin/true
    ret=0
    else
        # prepare for start
    touch "$errlogfile" 2>/dev/null
    if [ $? -ne 0 ]; then
         # failed to touch log file, probably insufficient permissions
        action $"Starting $prog: " /bin/false
        return 4
    fi
    chown mysql:mysql "$errlogfile"
    chmod 0640 "$errlogfile"
    [ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
    if [ ! -d "$datadir/mysql" ] ; then
        # First, make sure $datadir is there with correct permissions
        if [ ! -e "$datadir" -a ! -h "$datadir" ]
        then
        mkdir -p "$datadir" || exit 1
        fi
        chown mysql:mysql "$datadir"
        chmod 0755 "$datadir"
        [ -x /sbin/restorecon ] && /sbin/restorecon "$datadir"
        # Now create the database
        action $"Initializing MySQL database: " /usr/bin/mysql_install_db --datadir="$datadir" --user=mysql
        ret=$?
        chown -R mysql:mysql "$datadir"
        if [ $ret -ne 0 ] ; then
        return $ret
        fi
    fi
    chown mysql:mysql "$datadir"
    chmod 0755 "$datadir"
    # We check if there is already a process using the socket file,
    # since otherwise this init script could report false positive
    # result and mysqld_safe would remove the socket file, which
    # actually uses a different daemon.
    if fuser "$socketfile" &>/dev/null ; then
        echo "Socket file $socketfile exists. Is another MySQL daemon already running with the same unix socket?"
        action $"Starting $prog: " /bin/false
        return 1
    fi
    # Pass all the options determined above, to ensure consistent behavior.
    # In many cases mysqld_safe would arrive at the same conclusions anyway
    # but we need to be sure.  (An exception is that we don't force the
    # log-error setting, since this script doesn't really depend on that,
    # and some users might prefer to configure logging to syslog.)
    # Note: set --basedir to prevent probes that might trigger SELinux
    # alarms, per bug #547485
    $exec   --datadir="$datadir" --socket="$socketfile" \
        --pid-file="$mypidfile" \
        --basedir=/usr --user=mysql >/dev/null 2>&1 &
    safe_pid=$!
    # Spin for a maximum of N seconds waiting for the server to come up;
    # exit the loop immediately if mysqld_safe process disappears.
    # Rather than assuming we know a valid username, accept an "access
    # denied" response as meaning the server is functioning.
    ret=0
    TIMEOUT="$STARTTIMEOUT"
    while [ $TIMEOUT -gt 0 ]; do
        RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
        mret=$?
        if [ $mret -eq 0 ]; then
        break
        fi
        # exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,
        # anything else suggests a configuration error
        if [ $mret -ne 1 -a $mret -ne 11 ]; then
        echo "$RESPONSE"
        echo "Cannot check for MySQL Daemon startup because of mysqladmin failure."
        ret=1
        break
        fi
        echo "$RESPONSE" | grep -q "Access denied for user" && break
        if ! /bin/kill -0 $safe_pid 2>/dev/null; then
        echo "MySQL Daemon failed to start."
        ret=1
        break
        fi
        sleep 1
        let TIMEOUT=${TIMEOUT}-1
    done
    if [ $TIMEOUT -eq 0 ]; then
        echo "Timeout error occurred trying to start MySQL Daemon."
        ret=1
    fi
    if [ $ret -eq 0 ]; then
        action $"Starting $prog: " /bin/true
        chmod o+r $mypidfile >/dev/null 2>&1
        touch $lockfile
    else
        action $"Starting $prog: " /bin/false
    fi
    fi
    return $ret
}

stop(){
    if [ ! -f "$mypidfile" ]; then
        # not running; per LSB standards this is "ok"
        action $"Stopping $prog: " /bin/true
        return 0
    fi
    MYSQLPID=`cat "$mypidfile" 2>/dev/null`
    if [ -n "$MYSQLPID" ]; then
        /bin/kill "$MYSQLPID" >/dev/null 2>&1
        ret=$?
        if [ $ret -eq 0 ]; then
        TIMEOUT="$STOPTIMEOUT"
        while [ $TIMEOUT -gt 0 ]; do
            /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
            sleep 1
            let TIMEOUT=${TIMEOUT}-1
        done
        if [ $TIMEOUT -eq 0 ]; then
            echo "Timeout error occurred trying to stop MySQL Daemon."
            ret=1
            action $"Stopping $prog: " /bin/false
        else
            rm -f $lockfile
            rm -f "$socketfile"
            action $"Stopping $prog: " /bin/true
        fi
        else
        action $"Stopping $prog: " /bin/false
        fi
    else
        # failed to read pidfile, probably insufficient permissions
        action $"Stopping $prog: " /bin/false
        ret=4
    fi
    return $ret
}

restart(){
    stop
    start
}

condrestart(){
    [ -e $lockfile ] && restart || :
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status -p "$mypidfile" $prog
    ;;
  restart)
    restart
    ;;
  condrestart|try-restart)
    condrestart
    ;;
  reload)
    exit 3
    ;;
  force-reload)
    restart
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
    exit 2
esac

exit $?

时间: 2024-11-03 21:53:44

MYSQL简单安装配置的相关文章

Ubuntu搭建tftp服务器最简单安装配置

调试ARM的板子,要通过tftp下载到板子上,所以又要配置tftp服务器,真的烦死了- 因为之前已经在http://www.aliyun.com/zixun/aggregation/13835.html">Ubuntu下搭建过很多次tftp服务器了,但是一直记不住那一个配置文件的名字(记性太差),所以每次都要百度. 可是每次百度出来的结果都不一样,而且出入很大,有的过程相当的繁琐,不仅很麻烦,而且搞到最后还没有配置成功.所以干脆写个日志记下来. tftp服务器最简单安装配置 1.安装tft

iOS - MySQL 的安装配置

前言 提前下载好相关软件,且安装目录最好安装在全英文路径下.如果路径有中文名,那么可能会出现一些莫名其妙的问题. 提前准备好的软件: mysql-5.7.17-macos10.12-x86_64.dmg mysql-workbench-community-6.3.9-osx-x86_64.dmg MySQL 官网 1.下载安装 MySQL 1.1 下载 MySQL 访问 MySQL 下载官网,然后在页面中会看到 "MySQL Community Server" 下方有一个 "

Winodws下IIS/Apache+PHP+MySQL的安装配置

apache|iis|mysql 我写过的教程不多,而且大部分都是来源于别人的教程,不过,这里所介绍的,都是融入我所总结的经验.--引言 PHP的执行效率是有目共睹的,这也是我喜欢它的原因之一,和它称为绝妙搭档的Mysql以及Apache想融合,不能不惊叹其效率了.PHP更新也很快,这里列举了目前最新版本PHP4.3.2RC4(几乎没有BUG了,估计写完这篇不久后正式版就出了),和最新版本的Mysql4.0.13的安装过程. PHP的安装文件可以直接到 http://www.php.net/ 下

Linux系统下Mysql数据库安装配置整理

Mysql安装 1.通过官网下载mysql源码包.http://dev.mysql.com/downloads/ 点击MySQL Community Server,选择Source Code, 点击 Generic Linux (Architecture Independent), Compressed TAR Archive后的Download # wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz # t

CentOS6系统中GitLab+Nginx(SSL)+MySQL+Ruby安装配置

本文选择NGINX与MYSQL来配合GitLab实现web管理,数据存储等功能,配置过程中难点基本在GitLab的脚本修改,SSH秘钥连接,Nginx SSL证书等这些方面,作者也是耗费非常大的力气,结合很多文档的clue以及很多老外的debug comment,终于最终完成,希望在此给大家一个抛砖引玉的机会,了解到SCM(软件配置管理)其实也不是想象中那么小儿科,很多逻辑也着实需要下功夫investigation. 最后我是一路向北,我为我自己带盐.... 解决方案: 环境部署 操作系统  

Centos中mysql数据库安装配置与数据导入/备份

1.安装配置Mysql :本文安装的系统为Centos6.3:  代码如下 复制代码 yum list mysql # 查看有没有安装包 yum install mysql #  安装mysql客户端 yum list mysql-server # 查看有没有安装包 yum install mysql-server # 安装mysql 服务器端 #安装过后需要启动mysql服务 service mysqld start #或者/etc/init.d/mysqld start # 启动过后需要给m

windows服务器iis6+php+mysql的安装配置详解

以前都用apache,由于工作需要,要配置iis的php环境,网上找了一些资料,一下就配置好了,其实有了apache+php+mysql的经验,这个就很容易理解了.   现在趁热打铁,趁没忘记,把大致步骤总结一下.   第一步:下载程序   下载"php-5.2.0-win32.zip","mysql-noinstall-5.0.22-win32.zip",百度上面都有.   第二步:安装php   (1) 把下载的"php-5.2.0-Win32.zip

windows2003系统iis+php+mysql的安装配置详解

以前都用apache,由于工作需要,要配置iis的php环境,网上找了一些资料,一下就配置好了,其实有了apache+php+mysql的经验,这个就很容易理解了.   现在趁热打铁,趁没忘记,把大致步骤总结一下.   第一步:下载程序   下载"php-5.2.0-win32.zip","mysql-noinstall-5.0.22-win32.zip",百度上面都有.   第二步:安装php   (1) 把下载的"php-5.2.0-Win32.zip

Windows 2003中iis+php+mysql的安装配置图解

以前都用apache,由于工作需要,要配置iis的php环境,网上找了一些资料,一下就配置好了,其实有了apache+php+mysql的经验,这个就很容易理解了. 现在趁热打铁,趁没忘记,把大致步骤总结一下. 第一步:下载程序 下载"php-5.2.0-win32.zip","mysql-noinstall-5.0.22-win32.zip",百度上面都有. 第二步:安装php (1) 把下载的"php-5.2.0-Win32.zip" 复制到