MySQL数据库基础(2)安装实战 --2
1.3 安装相关包 1.3.1 cmake软件 cd /home/oldboy/tools/ tar xf cmake-2.8.8.tar.gz cd cmake-2.8.8 ./configure #CMake has bootstrapped. Now run gmake. gmake gmake install cd ../ 1.3.2 依赖包 yum install ncurses-devel -y 1.4 开始安装mysql 1.4.1 创建用户和组 groupadd mysql useradd mysql -s /sbin/nologin -M -g mysql 1.4.2 解压编译MySQL tar zxf mysql-5.5.32.tar.gz cd mysql-5.5.32 cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \ -DMYSQL_DATADIR=/application/mysql-5.5.32/data \ -DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ #可选字符集,不要求不写 -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \ -DENABLED_LOCAL_INFILE=ON \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \ -DWITH_FAST_MUTEXES=1 \ -DWITH_ZLIB=bundled \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_READLINE=1 \ -DWITH_EMBEDDED_SERVER=1 \ -DWITH_DEBUG=0 #-- Build files have been written to: /home/oldboy/tools/mysql-5.5.32 提示,编译时可配置的选项很多,具体可参考结尾附录或官方文档: make #[100%] Built target my_safe_process make install ln -s /application/mysql-5.5.32/ /application/mysql 如果上述操作未出现错误,则MySQL5.5.32软件cmake方式的安装就算成功了。
特别说明:
1、常规configure编译方式安装以及免编译方式安装等等的安装方法,都是上面过程不同,下面过程都相同
1.4.3初始化配置MySQL
1.查看默认模板配置文件
ll support-files.my*cnf
2.选择配置文件
ln -s /application/mysql-5.5.32/ /application/mysql
cp mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
测试环境选小的,生产环境可以根据硬件选择,例如:my-innodb-heavy-4G.cnf
3.配置环境变量
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
tail -1 /etc/profile
source /etc/profile
echo $PATH
4.初始化数据文件(容易出错的步骤)
ll /application/mysql/data/ #建立mysql数据文件目录
chown -R mysql.mysql /application/mysql/data/ #授权mysql用户访问mysql的安装目录
chmod -R 1777 /tmp/ #调整/tmp权限,否则初始化会错误。
./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
#安装mysql数据库文件,注意命令路径:
特别提示:
a.如果mysql5.0,5.1省略指定datadir会出错
b.正确提示
Installing MySQL system tables...
OK
Filling help tables...
OK
提示:俩个OK表示成功,有警告可以忽略,有ERROR要处理
5.设置常规方式启动关闭脚本
cd /home/oldboy/tools/mysql-5.5.32
/bin/cp support-files/mysql.server /etc/init.d/mysqld #拷贝mysql启动脚本到/etc/init.d/下。
chmod +x /etc/init.d/mysqld #授权700权限,即脚本可以执行
/etc/init.d/mysqld start #熟悉的重启方式又出现了
netstat -lntup|grep 3306
chkconfig mysqld on
chkconfig --list mysqld
6.登录mysql故障解决
![](https://img2018.cnblogs.com/blog/1669011/201909/1669011-20190918102944756-2083085283.png)
7.登录成功
mysql
mysql> select user,host from mysql.user; +------+-----------------------+ | user | host | +------+-----------------------+ | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | localhost.localdomain | | root | localhost.localdomain | +------+-----------------------+ 6 rows in set (0.00 sec) mysql> delete from mysql.user where user=''; Query OK, 2 rows affected (0.00 sec) mysql> select user,host from mysql.user; +------+-----------------------+ | user | host | +------+-----------------------+ | root | 127.0.0.1 | | root | ::1 | | root | localhost | | root | localhost.localdomain | +------+-----------------------+ 4 rows in set (0.00 sec) mysql> delete from mysql.user where host='www'; Query OK, 0 rows affected (0.00 sec) mysql> select user,host from mysql.user; +------+-----------------------+ | user | host | +------+-----------------------+ | root | 127.0.0.1 | | root | ::1 | | root | localhost | | root | localhost.localdomain | +------+-----------------------+ 4 rows in set (0.00 sec) mysql> delete from mysql.user where host='::1'; Query OK, 1 row affected (0.00 sec) mysql> select user,host from mysql.user; +------+-----------------------+ | user | host | +------+-----------------------+ | root | 127.0.0.1 | | root | localhost | | root | localhost.localdomain | +------+-----------------------+ 3 rows in set (0.00 sec) mysql> drop database test; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec)
/application/mysql//bin/mysqladmin -u root password '123456'
mysql -uroot -p123456