在linux下mysql 5.5安装
1、安装所需要系统库相关库文件
yum remove mysql-server mysql mysql-devel -y
yum install gcc gcc-c++ ncurses-devel libtool openssl-devel -y
2、创建mysql安装目录
mkdir -p /usr/local/mysql/
3、创建数据存放目录
mkdir -p /service/mysql/
4、创建用户和用户组与赋予数据存放目录权限
groupadd mysql
useradd -g mysql mysql
chown mysql.mysql -R /service/mysql/
5、安装cmake(mysql5.5以后是通过cmake来编译的)
wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
tar zxvf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./configure
make && make install
6、下载解压mysql 5.5.27
wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.5/mysql-5.5.27.tar.gz
tar zxvf mysql-5.5.27.tar.gz
cd mysql-5.5.27
7、编辑mysql
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_DATADIR=/service/data/\
-DMYSQL_UNIX_ADDR=/service/data/mysqld.sock\
-DWITH_INNOBASE_STORAGE_ENGINE=1\
-DSYSCONFDIR=/etc\
-DEXTRA_CHARSETS=all\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8-general_ci\
-DMYSQL_USER=mysql\
-DWITH_DEBUG=0
-DMYSQL_UNIX_ADDR=/service/data/mysqld.sock\
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/service/data/\
-DMYSQL_USER=mysql
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/service/data/ -DMYSQL_UNIX_ADDR=/service/data/mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_DEBUG=0
源代码配置选项说明:
//mysql安装的主目录,5.5.8版本默认为/usr/local/mysql,所以可以不添加
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
//mysql数据保存的路径,自定义
-DMYSQL_DATADIR=/home/system_username/mysql/mysqldata
//mysql配置文件地址------The default my.cnf option file directory
-DSYSCONFDIR=/etc
//Compile storage engine xxx statically into server
/*Storage engines are built as plugins. You can build a plugin as a static module (compiled into the server)
*or a dynamic module (built as a dynamic library that must be installed into the server using the INSTALL
*PLUGIN statement or the --plugin-load option before it can be used). Some plugins might not support static
*or dynamic building.
*/
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
//Unix socket file
/*
*The Unix socket file path on which the server listens for socket connections. This must be an absolute path
*name. The default is /tmp/mysql.sock
*/
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock
//数据库服务器TCP/IP连接的监听端口,默认为3306
-DMYSQL_TCP_PORT=3306
//Whether to enable LOCAL capability in the client library for LOAD DATA INFILE
//默认为关闭,这里开启
-DENABLED_LOCAL_INFILE=1
//数据库编码设置
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8-general_ci
8、make && make install
9、
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
bash scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/service/data/
/etc/init.d/mysqld start
/usr/local/mysql/bin/mysql -u root -p
mysql>use mysql ;
mysql>update user set password=PASSWORD("admin123456") where user='root';
mysql>FLUSH PRIVILEGES;
10、查看端口
netstat -anp |grep mysqld
11、修改root用户远程访问的权限:
/usr/local/mysql/bin/mysql -u root -p
# mysql -uroot -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin123456' IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
如果你想允许用户root从ip为192.168.10.24的主机连接到mysql服务器,并使用123456作为密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.3.253' IDENTIFIED BY 'admin123456' WITH GRANT OPTION;
12、使用服务器启动和关闭
service mysqld restart
service mysqld start
service mysqld stop
修改某表的自增长列重新从1开始
ALTER TABLE soft AUTO_INCREMENT=1
13、远程连接不上时,检查防火墙
iptables -L
关闭防火墙
service iptables stop