mysql -uroot -pgameol32! 或者
mysql -uroot -p 再输入密码 进入mysql控制台
mysql控制台模式下:
show status; 查看mysql所有状态
show processlist; 普通用户自己的当前连接数,root用户可以查看所有用户的当前连接数
show status like ‘%connections%‘; 关键字查找
shell命令行模式下:
mysqladmin -uroot -p variables 查看mysql当前运行状态
修改mysql最大连接数的方法:
一、即时修改,即时生效
mysql -uroot -p
mysql> set GLOBAL max_connections=1000; 默认最大连接数100
mysql> show processlist; 显示当前运行的query请求
mysql> show status; 显示当前的状态
mysql> exit; 退出mysql控制台
mysqladmin -uroot -p variables
系统重启失效
可以写脚本,在系统启动初始化时执行脚本,修改最大连接数
二、修改配置文件,重启生效
以centos 5.4 下面的mysql 5.0.83 rpm版本为例说明:
找到/usr/bin/mysqld_safe编辑它,找到mysqld启动的那两行,在后面加上参数 :
-O max_connections=1000
用红字特别说明:
if test -z "$args"
then
$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-external-locking -O max_connections=1000 >> $err_log 2>&1
else
ev al "$NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-external-locking $args -O max_connections=1000 >> $err_log 2>&1"
fi
这段代码很不好找,在下也无法说清楚它具体在哪个位置。不过建议从最后往前找会比较快。
重启mysql服务:# service mysql restart
查看当前最大连接数:# /usr/local/mysql/bin/mysqladmin -uroot -p variables
输入root数据库账号的密码后可看到
max_connections 1000 即新改动已经生效。
三、
修改mysqld的启动文件/etc/init.d/mysqld 在start()函数末尾添加代码
mysql -e ‘set GLOBAL max_connections=1000;‘如
start(){
[ -x $exec ] || exit 5
# check to see if it‘s already running
RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
if [ $? = 0 ]; then
# already running, do nothing
action $"Starting $prog: " /bin/true
ret=0
elif 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"
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"
# 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
STARTTIMEOUT=120
while [ $STARTTIMEOUT -gt 0 ]; do
RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1` && break
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 STARTTIMEOUT=${STARTTIMEOUT}-1
done
if [ $STARTTIMEOUT -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
touch $lockfile
else
action $"Starting $prog: " /bin/false
fi
fi
mysql -e ‘set GLOBAL max_connections=1000;‘
return $ret
}
四、Windows系统修改
进入MYSQL安装目录 打开MYSQL配置文件 my.ini 或 my.cnf查找 max_connections=100 修改为 max_connections=1000 服务里重起MYSQL即可。此方法用于Windows下的mysql设置,简单方便。如果是Linux的话,请看下面。